|
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main(void)
{
int a;
time_t t;
int num[6];
int check, temp;
srand((unsigned) time(&t));
printf("Six Random Numbers between 1 and 45\n\n");
a=0;
do{
temp = (rand()%45)+1; //난수 발생
check = 0;
for(int i=0; i<6; i++) // 같은수 있는지 비교
{
if(temp == num[i]) check = 1;
}
if(!check) // 같은 수가 없으면
{
num[a] = temp; // 난수 저장
a++; // 다음으로...
}
}while(a<6);
// 숫자 정렬
for(int i=0; i<5; i++)
{
for(int j=i+1; j<6; j++)
{
if(num[i]>num[j]) // 앞의 숫자가 크면 바꾼다.
{
temp = num[i];
num[i] = num[j];
num[j] = temp;
}
}
}
// 화면 출력부분
for(int i=0; i<6; i++)
{
printf("%d\n",num[i]);
}
return 0;
}
|