Contents

Develop
2013.04.23 15:07

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

Views 7193 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
277 Develop [iphone] view에 대한 조사 ㅡ,.ㅡ; file hooni 2013.04.23 54121
276 Develop [iphone] 아이폰 어플 모음 ㅋㅋ secret hooni 2013.04.23 13707
275 Develop [iphone] 파일 업로드 샘플 코드 ㅎㅎ secret hooni 2013.04.23 11120
274 Develop [iphone] 화면 전환 Portrait & Landscape Mode hooni 2013.04.23 22364
273 Develop [Javascript][Ajax] 자바스크립트 강의 산출물 file hooni 2019.10.05 815
272 Develop [java] Interface 와 abstract hooni 2013.04.23 8734
271 Develop [java] netty (비동기 이벤트 방식 네트워크 프레임워크) 사용법 #1 (server) 1 hooni 2015.01.02 2325
270 Develop [java] netty (비동기 이벤트 방식 네트워크 프레임워크) 사용법 #2 (client) hooni 2015.01.02 2135
269 Develop [java] RGB 색상 조절 버튼.. 스윙(swing) file hooni 2013.04.23 7871
268 Develop [java] RGB코드를 HEX코드로 변환하는 코드 ㅎㅎ hooni 2013.04.23 8031
267 Develop [java] Sieve of Eratosthenes (에라토스테네스의 체) hooni 2013.04.23 9354
266 Develop [java] 거스름돈 계산.. swing 사용 file hooni 2013.04.23 9465
Board Pagination Prev 1 ... 43 44 45 46 47 48 49 50 51 52 ... 71 Next
/ 71