Notice
Recent Posts
Recent Comments
Creative Code
lotto.c (로또 번호 생성) 본문
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
int lotto[7];
srand(time(NULL));
while (1) { // 서로다른 번호 6개 + 보너스 번호 생성
int check = 0;
for (int i = 0; i<7; i++){
lotto[i] = rand()%45 +1;
}
for (int i = 0; i<6; i++){
for (int j = i+1; j<7; j++){
if (lotto[i] == lotto[j]){
check = 1;
}
}
}
if (check == 0) {
printf("당첨 번호 : ");
for (int i = 0; i<6; i++){
printf("%d, ",lotto[i]);
}
printf(" 보너스 번호 : %d \n",lotto[6]);
break;
}
}
return 0;
}
'C Programming' 카테고리의 다른 글
pointer.c(포인터) (1) | 2023.08.02 |
---|---|
sumMatrix.c( 다차원배열의 원소의 합) (0) | 2023.08.02 |
baseball.c(숫자 야구게임) (0) | 2023.08.02 |
dice.c(주사위 값 srand함수) (0) | 2023.08.02 |
dice.c (주사위 값 rand함수) (0) | 2023.08.02 |