Recent Posts
printf("ho_tari\n");
lotto 본문
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define lotto_max 45
#define lotto_num 7
int main(void)
{
int lottonum[lotto_num];
int duplicate;
srand(time(NULL));
printf("< LOTTO >\n");
printf("Randomly choose %d numbers from 1 ~ %d\n", lotto_num, lotto_max);
for (int i = 0; i < lotto_num; ++i)
{
int randomnum;
do
{
randomnum = rand() % lotto_max + 1;
duplicate = 0;
for (int j = 0; j < i; ++j)
{
if (lottonum[j] == randomnum)
{
duplicate = 1;
break;
}
}
}while(duplicate);
lottonum[i] = randomnum;
}
printf("--------------------------------------\n");
printf("LOTTO Numbers\n");
for (int i = 0; i < lotto_num; ++i)
{
printf("%d ", lottonum[i]);
}
printf("\n");
return 0;
}
<compile 결과>
'C' 카테고리의 다른 글
multiplyTable (0) | 2023.09.01 |
---|---|
maxMidMin (0) | 2023.09.01 |
literal (0) | 2023.09.01 |
limits (0) | 2023.09.01 |
letterAttribute2 (0) | 2023.09.01 |