ADVERTISEMENT
ADVERTISEMENT

C program to find factorial using recursion.

In this program, we will read a number and then find (calculate) of factorial of that number using recursion.
What is factorial: Factorial of a number is the product of that number with their all below integers.
For example (Factorial of 5) is: !5 = 5*4*3*2*1 = 120

Factorial program using recursion

/*C program to find factorial of a number using recursion.*/
 
#include <stdio.h>
 
//function for factorial
long int factorial(int n)
{   
    if(n==1)    return 1;
    return n*factorial(n-1);
}
int main()
{
    int num;
    long int fact=0;
     
    printf("Enter an integer number: ");
    scanf("%d",&num);
     
    fact=factorial(num);
    printf("Factorial of %d is = %ld",num,fact);
    printf("\n");   
    return 0;
}

Output

Enter an integer number: 5
Factorial of 5 is = 120

C Recursion Programs »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.