forked from HarshCasper/NeoAlgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
doublefactorial.c
61 lines (55 loc) · 1.1 KB
/
doublefactorial.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
51
52
53
54
55
56
57
58
59
60
61
#include <stdio.h>
int iterative_doublefactorial(int n) {
int res = 1;
for (int i = n; i > 0; i -= 2) {
if (n == 0 || n == 1)
return res;
else
res = res * i;
}
}
int recursive_doublefactorial(int n) {
if (n == 0 || n == 1)
return 1;
else
return n * recursive_doublefactorial(n - 2);
}
int main() {
int n;
printf("Enter the number :");
scanf("%d", & n);
int k;
do {
printf("Enter the choice below :\n1.Iterative solution \n2.Recursive Solution \n3.Exit \n");
scanf("%d", & k);
switch (k) {
case 1:
printf("The Double Factorial is : %d\n", iterative_doublefactorial(n));
break;
case 2:
printf("The Double Factorial is : %d\n", recursive_doublefactorial(n));
break;
}
} while (k != 3);
return 0;
}
/*
Enter the number :7
Enter the choice below :
1.Iterative solution
2.Recursive Solution
3.Exit
1
The Double Factorial is : 105
Enter the choice below :
1.Iterative solution
2.Recursive Solution
3.Exit
2
The Double Factorial is : 105
Enter the choice below :
1.Iterative solution
2.Recursive Solution
3.Exit
3
*/