SnapTimes

News In A Snap!!

C++ Programs: Calculate Factorial using Recursion

June 2, 2015

 C++_Main

What is Factorial?

In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example, The value of 0! is 1, according to the convention for an empty product, factorial four ( 4! ) is equal to 24.

Code


/* Program to calculate factorial using recursion */
#include<iostream.h>
#include<conio.h>
long int factorial(long int n) {
 if (n==0) {
 return 1;
 } else return (n * factorial(n-1));
}

int main() {
 clrscr();
 cout << "Find factorial of? ";
 long int n; cin >> n;
 cout << "Factorial is ";
 cout << factorial(n);
 getch();
 return 0;
}

Output:

fact


SnapTimes.in | Get Tech Addicted...
About Us | Contact Us | ©2017