로또 추첨 프로그램

뻘글들/낚시글들 | 2009/05/11 19:38 | Posted by DMW
크리에이티브 커먼즈 라이선스
Creative Commons License
#include <stdio.h>

void swap(int *x, int *y) {
    int temp = *x;
    *x = *y;
    *y = temp;
}

void random_shuffle(int *array, int size) {
    int i, temp;
    
    for(i = 2; i < size; i++)
        swap(&array[i], &array[rand() % i]);
}

int main(int argc, char **argv) {
    int i;
    int lotto[45];
    
    for(i = 0; i < 45; i++)
        lotto[i] = i + 1;

    random_shuffle(lotto, 45);

    for(i = 0; i < 5; i++)
        printf("%d\n", lotto[i]);

    return 0;
}


Output:
1
2
3
4
5
6
30
13
17
26

저작자 표시 비영리 동일 조건 변경 허락

'뻘글들 > 낚시글들' 카테고리의 다른 글

로또 추첨 프로그램  (2) 2009/05/11
C언어 배열을 함수 파라미터로 넘기는 방법  (2) 2009/05/11
TAG ,

댓글을 달아 주세요

  1. Favicon of http://btd86.tistory.com/ BlogIcon 숙신 2009/07/14 22:26  댓글주소  수정/삭제  댓글쓰기

    형, 이거 코드패드에서 한거 맞나요?
    어떻게 한거에요??