-
Notifications
You must be signed in to change notification settings - Fork 0
/
Factorial.c
50 lines (40 loc) · 974 Bytes
/
Factorial.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
42
43
44
45
46
47
48
49
50
#include <stdio.h>
#include <time.h>
int Factorial(int num); //Factorial 코드
int Iteration(int num); //Interation 코드
int main(void)
{
int start_time = 0, end_time = 0;
float time = 0.0f;
start_time = clock();
int num = 0;
int tempnum = 17; //몇 번 곱할 건가요?
//팩토리얼 구하는 곳!!
num = Factorial(tempnum);
printf("Use Interation\n%d! = %d\n\n", tempnum, num);
end_time = clock();
time = (float)(end_time - start_time) / CLOCKS_PER_SEC;
printf("duration : %f", time);
//Iteration
start_time = clock();
num = Iteration(tempnum);
printf("Use Interation\n%d! = %d\n\n", tempnum, num);
end_time = clock();
time = (float)(end_time - start_time) / CLOCKS_PER_SEC;
printf("duration : %f", time);
return 0;
}
int Factorial(int num)
{
if (num == 1)
return 1;
else
return num * Factorial(num - 1);
}
int Iteration(int num)
{
int a = 1;
for (int i = 1; i <= num; i++)
a *= i;
return a;
}