pc-ip-14.c (831B)
1 /* 2 * Author: Amit Dutta (amitdutta4255@gmail.com) | Date: 05 Jan 2026 3 * Repo: https://github.com/notamitgamer/bsc 4 * License: MIT 5 */ 6 7 /* 8 * Question 14: 9 * Write a program to calculate the factorial of a number using recursive and iterative function. 10 */ 11 12 #include <stdio.h> 13 14 long long int fact_rec(int); 15 long long int fact_ite(int); 16 17 int main() 18 { 19 int n; 20 printf("Enter the number: "); 21 scanf("%d", &n); 22 printf("\nFactorial of %d (Recursion): %lld", n, fact_rec(n)); 23 printf("\nFactorial of %d (Iteration): %lld", n, fact_ite(n)); 24 return 0; 25 } 26 27 long long int fact_ite(int n) 28 { 29 int i, pd = 1; 30 for (i = 1; i <= n; i++) 31 { 32 pd *= i; 33 } 34 return pd; 35 } 36 37 long long int fact_rec(int n) 38 { 39 if (n == 0) 40 { 41 return 1; 42 } 43 else 44 { 45 return n * fact_rec(n - 1); 46 } 47 }