게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
[프로그래밍 배틀] 가장 비효율적으로 1~100까지 더하기
게시물ID : programmer_449짧은주소 복사하기
작성자 : 너는고소다
추천 : 7
조회수 : 1894회
댓글수 : 39개
등록시간 : 2014/01/16 10:36:40
예전에 프갤이랑 다른데 올렸던건데 재밌어요

가장 비효율적으로 더하기!

배틀뜹시다!



#include <stdio.h>  #include <stdlib.h>  #include <time.h>        #define SUM_MAX 100        int main(int argc, char *argv[]) {          int n, i, sum, checksum;          int check[SUM_MAX];                n=i=sum=checksum=0;                for(i=0; i<SUM_MAX; i++) {                  check[i] = i+1;          }             sleep(1);          srand(time(NULL)) ;                while(1) {                  n = rand()%SUM_MAX + 1;                        if((n > 0) && (n < SUM_MAX+1)) {                          if(check[n-1]>0)                                  sum += n;                          check[n-1] = 0;                                checksum = 0;                          for(i=0; i<SUM_MAX; i++) {                                  checksum += check[i];                          }                          if(checksum==0)                                  break;                  }          }                printf("result : %d\n",sum);                return 0;  }
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호