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 [c++]현승이가 보내준 동영상 암호화 자료.. 볼것.. file hooni 2003.04.23 9759
276 Develop [php] 자주 쓰는 PHP 함수와 예제 hooni 2013.04.23 9820
275 Develop [js] 자바스크립트로 응용프로그램 실행 ㅎㅎ hooni 2003.04.23 9857
274 Develop [c] 간단한 링크드 리스트(linked list) 자료형 예제.. hooni 2003.04.23 9870
273 Develop [php] 니우쪽지다.. 받아라~ ^^ file hooni 2003.04.23 9874
272 Develop [css] 스크롤바 안생기게 hooni 2003.04.23 9919
271 Develop [c++] 데이터 압축 프로그램 소스 (lzw) file hooni 2013.04.23 9975
270 Develop [js] 이벤트 전파 3단계 hooni 2013.12.18 9998
269 Develop [c++] 퍼즐 버블버블 간단한 원리(사용공식) file hooni 2013.04.23 10004
268 Develop [js] jQuery 배열 루프(each) hooni 2013.12.17 10025
267 Develop [c] 문자열 뒤집기 (문자열 거꾸로 출력하는 간단소스) hooni 2003.04.23 10061
266 Develop [linux] 쉘 스크립트를 이용한 BBS hooni 2003.04.23 10084
Board Pagination Prev 1 ... 43 44 45 46 47 48 49 50 51 52 ... 71 Next
/ 71