Program to find factorial of a number using recursion


Default

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Write a program to find factorial of a given number using recursion
// Eg: 3!=6, 5!=120, 0!=1 …..
// Author: admin@aimforjob.com
 
#include <stdio.h>
int factorial(int );
int main()
{
    int inp;
    printf(“Enter a number:”);
    scanf(“%d”,&inp);
    if (inp<0)
        printf(“Factorial doesnot exist…!n”);
    else
        printf(“Factorial value=%dn”,factorial(inp));
    return 0;
}
int factorial(int n)
{
    if(n==0)
        return 1;
    else
        return n*factorial(n-1);
}