pc-ip-14.c ​
Metadata ​
- Author — Amit Dutta (amitdutta4255@gmail.com)
- Last updated — 05 Jan 2026
- License — MIT
Problem Statement ​
Problem Statement
Question 14: Write a program to calculate the factorial of a number using recursive and iterative function.
Source Code ​
Printing the code
To print this file, open it on GitHub and click Raw before printing, or use the Download Raw button above and print directly from that page.
c
#include <stdio.h>
long long int fact_rec(int);
long long int fact_ite(int);
int main()
{
int n;
printf("Enter the number: ");
scanf("%d", &n);
printf("\nFactorial of %d (Recursion): %lld", n, fact_rec(n));
printf("\nFactorial of %d (Iteration): %lld", n, fact_ite(n));
return 0;
}
long long int fact_ite(int n)
{
int i, pd = 1;
for (i = 1; i <= n; i++)
{
pd *= i;
}
return pd;
}
long long int fact_rec(int n)
{
if (n == 0)
{
return 1;
}
else
{
return n * fact_rec(n - 1);
}
}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
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