C Program Find Factorial by Recursion

#include<stdio.h> // prototype for user defined recursive function long factorial(int); // main function int main() { int n; long fact; printf("Enter a number to find its factorial using Recursion="); scanf("%d", &n); if (n < 0) printf("Factorial of negative integers isn't defined.\n"); else { fact = factorial(n); printf("%d! = %ld", n, fact); } return 0; } // Function definition for recursive factorial function long factorial(int n) { if (n == 0) // Base case because factorial of 0 is 1 return 1; else return (n*factorial(n-1)); //Recursive, call to itself }

Output

Enter a number to find its factorial using Recursion=4

4! = 24

——————————–

Process exited after 30.59 seconds with return value 0

Press any key to continue . . .

321 total views, 2 views today

This website was… how do you say it? Relevant!! Finally I’ve found something that helped me. Thanks a lot!

Pingback: Recursion in Java Explained With Examples | EasyCodeBook.com

Pingback: Python Recursive Function Check Palindrom String | EasyCodeBook.com

Pingback: Python Recursion With Example Recursive Function | EasyCodeBook.com