C Programming

lotto.c (로또 번호 생성)

빛하루 2023. 8. 2. 12:34
#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;
}