-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04_Operator.c
41 lines (24 loc) · 1.06 KB
/
04_Operator.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
// +, - , * , /, %
// % 나머지 연산자(modulate operator)
// 11 % 2 = 1
// 임의의 숫자를 일정한 범위의 숫자로 만들때 사용합니다.
// direction: 0: 북쪽, 1: 남쪽, 2: 서쪽, 3: 동쪽
int main() {
srand(time(NULL)); // 현재 시간으로 난수 초기값을 만듦
int randValue = rand(); // 난수 발생
int direction = randValue % 4; // 0 ~ 3 사이의 숫자로 만듦
printf("randValue = %d, direction = %d\n", randValue, direction);
randValue = rand(); // 난수 발생
direction = randValue % 4; // 0 ~ 3 사이의 숫자로 만듦
printf("randValue = %d, direction = %d\n", randValue, direction);
randValue = rand(); // 난수 발생
direction = randValue % 4; // 0 ~ 3 사이의 숫자로 만듦
printf("randValue = %d, direction = %d\n", randValue, direction);
randValue = rand(); // 난수 발생
direction = randValue % 4; // 0 ~ 3 사이의 숫자로 만듦
printf("randValue = %d, direction = %d\n", randValue, direction);
return 0;
}