Notice
Recent Posts
Recent Comments
Creative Code
main.c(함수 선언) 본문
#include <stdio.h>
#include <time.h>
void my_srand(int); // function declaration 함수 선언(미리 선언을 해두면 main 함수 밑에 함수를
쓰거나 다른.c파일에 분리를 하더라도 참조할 수 있다.
int my_rand(void);
int main(void)
{
my_srand(time(NULL));
for (int i = 1; i<=10; i++) {
int num = my_rand();
printf("%d\n",num);
}
return 0;
}
int seed;
void my_srand(int s) // function definition
{
seed = s;
}
int my_rand(void)
{
seed = 1103515245 * seed +12345;
return ((unsigned)(seed/65536)%32768);
}
'C Programming' 카테고리의 다른 글
main.c(serial함수) (0) | 2023.08.04 |
---|---|
main.c(rand함수) (0) | 2023.08.04 |
main.c (랜덤함수 라이브러리 생성) (0) | 2023.08.04 |
swap3.c(전역변수 사용) (0) | 2023.08.04 |
bowling.c(볼링 점수 계산) (0) | 2023.08.03 |