google.com, pub-8786015629279405, DIRECT, f08c47fec0942fa0 Write a Program to Find Factorial of a Number using Recursion in C

Write a Program to Find Factorial of a Number using Recursion in C

0

 



/*Write a Program to Find Factorial of a Number using Recursion in C.*/

 

#include<stdio.h> 

 

long factorial(int n) 

{ 

  if (n == 0) 

    return 1; 

  else 

    return(n * factorial(n-1)); 

} 

  

void main() 

{ 

  int number; 

  long fact; 

  printf("Enter a number: "); 

  scanf("%d", &number);  

  

  fact = factorial(number); 

  printf("Factorial of %d is %ld\n", number, fact); 

  return 0; 

} 

 

Output

 

Enter a number: 8

Factorial of 8 is 40320

 


Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

Thank you for your interest 😊

We will back shortly after reviewing...

Thank you for your interest 😊

We will back shortly after reviewing...

Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !
To Top