Contents

Develop
2013.04.23 15:07

[c] 로또(Lotto) 번호 생성기

Views 7192 Comment 0
Atachment
Attachment '1'
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
단, 6번의 루프로 해결 버전 입니다 >0<

#include <stdio.h> 
#include <stdlib.h> 
#include <unistd.h> 
#include <time.h> 

int ball[46] ={ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
        11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
        21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
        31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
        41, 42, 43, 44, 45, 46 };

int get_number(void){ 
        return (int)(rand()) % 45 + 1;
}

int main(void){
        int i, idx, tmp;
        
        srand((unsigned)time(NULL) * (unsigned)getpid());
        
        for(i=0; i<6; i++){
                idx = get_number();
                // ball의 인덱스와 ball의 i의 값을 바꾸어 줍니다.
                tmp = ball[idx];
                ball[idx] = ball[i];
                ball[i] = tmp;
        }
        
        printf("oops : %d %d %d %d %d %d\n", ball[0], ball[1], ball[2], ball[3], ball[4], ball[5]);
        
        return 0; 
}

출처 : http://myohan.egloos.com


?

List of Articles
No. Category Subject Author Date Views
301 Develop [ios] DJBros. (DJ요맨~) file hooni 2013.04.23 28138
300 Develop [ios] 테이블뷰셀/뷰에 배경 패턴 넣기.. hooni 2013.04.23 29859
299 Develop [ios] 자주 쓰는 패턴과 API hooni 2013.04.23 17733
298 Develop [ios] UIColor 지정에서 RGB define ㅎㅎ hooni 2013.04.23 22969
297 Develop [ios] UILabel top alignㅎㅎ hooni 2013.04.23 22894
296 Develop [ios] NSData 클래스에 대해 (NSData <-> char*) hooni 2013.04.23 26593
295 Develop [ios] iCloud관련 저장 디렉토리 hooni 2013.04.23 29677
294 Develop [ios] 디렉토리 하하하.. hooni 2013.04.23 32661
293 Develop [iphone] performSelector:withObject:afterDelay: 에 대한 내용 hooni 2013.04.23 65903
292 Develop [iphone] 화면 전환 Portrait & Landscape Mode hooni 2013.04.23 22361
291 Develop [node.js] nodejs 기본 설치 hooni 2013.04.23 26327
290 Develop [node.js] 지금 하고 있는거.. file hooni 2013.04.23 27025
Board Pagination Prev 1 ... 41 42 43 44 45 46 47 48 49 50 ... 71 Next
/ 71