Last active
June 8, 2016 15:08
-
-
Save mingyu-kwak/19cb2d578b039d391bca191c28442695 to your computer and use it in GitHub Desktop.
로또 생성기
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <time.h> | |
| void not_duplicate_rand(int data[], int size); | |
| void insert_sort(int data[], int size); | |
| void delay(clock_t n); | |
| enum { | |
| MAX = 45, | |
| LIMIT = 6, | |
| TRUE = 1, | |
| FALSE = 0 | |
| }; | |
| void main() { | |
| int i, repeat; | |
| int lotto[LIMIT]; | |
| for (repeat = 0; repeat < 10; repeat++) { | |
| not_duplicate_rand(lotto, LIMIT); | |
| for (i = 0; i < LIMIT; i++) { | |
| printf("%2d ", lotto[i]); | |
| } | |
| printf("\n"); | |
| delay(1000); | |
| } | |
| } | |
| void not_duplicate_rand(int data[], int size) { | |
| int i, sw, temp; | |
| int index = 0; | |
| srand((unsigned int)time(NULL)); | |
| while (index < size) { | |
| temp = rand() % MAX + 1; | |
| sw = FALSE; | |
| for (i = 0; i <= index - 1; i++) { | |
| if (data[i] == temp) { | |
| sw = TRUE; | |
| break; | |
| } | |
| } | |
| if (sw == FALSE) { | |
| data[index] = temp; | |
| index += 1; | |
| } | |
| } | |
| insert_sort(data, size); | |
| } | |
| void insert_sort(int data[], int size) { | |
| int i, j; | |
| int ins_data; | |
| for (i = 1; i < size; i++) { | |
| ins_data = data[i]; | |
| for (j = i - 1; j >= 0; j--) { | |
| if (data[j] > ins_data) | |
| data[j + 1] = data[j]; | |
| else | |
| break; | |
| } | |
| data[j + 1] = ins_data; | |
| } | |
| } | |
| void delay(clock_t n) { | |
| clock_t start = clock(); | |
| while (clock() - start < n); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment