Contents

Develop
2013.04.23 15:07

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

조회 수 7179 댓글 0
Atachment
첨부 '1'
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
단, 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
번호 분류 제목 글쓴이 날짜 조회 수
429 Develop [spring] 스프링 IoC/DI hooni 2013.04.23 11399
428 System/OS [linux] iptables 명령어 매뉴얼(options) hooni 2003.04.23 11402
427 System/OS [linux] vi 편집기 간단한 명령과 환경설정 hooni 2003.04.23 11406
426 Develop [switch] 시스코 카탈리스트(Cisco Catalyst) 2950 미러링 설정 hooni 2013.04.23 11416
425 Develop [c++] mfc 조건별 파일 검색 프로그램 소스 ㅋㅋ 19 file hooni 2013.04.23 11431
424 System/OS [linux] GD 라이브러리 설치 방법.. file hooni 2013.04.23 11454
423 Develop [c++] 기초강좌 #01(입출력,영역지정) hooni 2003.04.23 11458
422 Develop [ios] UIButton multi-line iOS7 hooni 2014.01.09 11459
421 Develop 페이팔에서 돈 찾기 (Paypal withdraw) file hooni 2014.02.20 11463
420 Develop [c++] 기초강좌 #02(레퍼런스,메모리할당) hooni 2003.04.23 11473
419 Develop [c++] mfc 이용한 기본적인 형변환 예제 hooni 2013.04.23 11488
418 Develop [c] 테트리스(Tetris) 게임(도스용) 소스코드 file hooni 2003.04.23 11507
Board Pagination Prev 1 ... 58 59 60 61 62 63 64 65 66 67 ... 98 Next
/ 98