728x90
#include <stdio.h>
#include <stdlib.h> <<- 랜덤 함수를 쓸 시 필요
#include <time.h> <<- 랜덤 함수를 쓸 시 필요
/*
난수
- rand()
*/
int main()
{
printf("%d, ", rand() % 10 + 1); // 1 ~ 10의 사이의 랜덤값 출력
printf("%d, ", rand() % 10 + 1);
printf("%d, ", rand() % 10 + 1);
printf("%d, ", rand() % 10 + 1);
printf("%d, ", rand() % 10 + 1);
printf("\n\n");
//srand()
srand((unsigned int)time(NULL)); // 이것을 안써줄시 같은 값만 나옴 , seed를 변경해주어 각기 다른값이 나오도록 함
printf("%d, ", rand() % 10 + 1);
printf("%d, ", rand() % 10 + 1);
printf("%d, ", rand() % 10 + 1);
printf("%d, ", rand() % 10 + 1);
printf("%d, ", rand() % 10 + 1);
printf("\n\n");
return 0;
}
728x90
'Basic C Language' 카테고리의 다른 글
#10. for(반복문) (0) | 2023.04.12 |
---|---|
#9. While (반복문) (0) | 2023.04.12 |
#7. Switch (조건문) (0) | 2023.04.12 |
#6. If (조건문) (0) | 2023.04.12 |
#5. Type_Casting (0) | 2023.04.05 |