Develop
2013.04.23 15:07

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

조회 수 7183 추천 수 0 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
181 Develop How to Test SMTP AUTH using Telnet hooni 2018.04.05 1582
180 System/OS 네트워크 용어 정리 file hooni 2022.11.20 1574
179 Develop What is difference between Get, Post, Put and Delete? hooni 2018.02.28 1561
178 Develop [swift] popToRoot 모달뷰, 네비게이션컨트롤러 한꺼번에 닫기 file hooni 2021.01.29 1552
177 System/OS SSH Passwordless Login Using SSH Keygen in 5 Easy Steps file hooni 2019.11.22 1530
176 System/OS How to Install and Use wget on Mac file hooni 2020.09.03 1529
175 System/OS RPA란? 어디에 어떻게 쓰이고 누가 만드나? file hooni 2020.01.28 1511
174 Etc 아이폰의 터치스크린 정확도 file hooni 2015.04.01 1510
173 Develop [ios] Swift 4 String, Date, DateFormatter 예제 hooni 2018.10.18 1505
172 System/OS Configure Postfix to Use Gmail SMTP on Ubuntu 18.04 file hooni 2020.02.07 1486
171 Etc 모바일 프로그래머가 갖추어야 할 필수 역량 file hooni 2017.02.16 1473
170 Develop [ios] How to set up clang formatter hooni 2015.09.17 1468
169 Develop [android] 간단한 SQLIite 예제 hooni 2017.06.14 1455
168 System/OS [mac] Mac OS 패키지 매니저, HomeBrew file hooni 2015.01.03 1454
167 Develop [php] 한글 문자열 자르기 (utf-8) hooni 2015.11.10 1452
166 Etc ISMS 인증기준 – 정보보호대책 (시스템개발보안) file hooni 2016.12.01 1451
Board Pagination Prev 1 ... 61 62 63 64 65 ... 74 Next
/ 74