by CodeChum Admin
I love facts. In fact, I dream a lot about facts. Ever since I was a kid, all I ever think of are facts. And that's a fact!
I don't know if that made any sense to you but I think you know about factorials, hmm? In Mathematics, a factorial of a number is the product of all the numbers from 1 up to that number. There is one exception though and that is the factorial of 0 which is 1.
Instructions:
Input
1. Integer to be processed
Output
Enter·n:·3
Factorial·of·3·is·6
#include <iostream>
using namespace std;
int getFactorial(int n) {
if (n <= 1) {
return 1;
}
return n*getFactorial(n-1);
}
int main() {
int n;
cout << "ENter n: ";
cin >> n;
int fact = getFactorial(n);
cout <<"Ractorial of " << n << " is " << fact << endl;
return 0;
}
Comments
Leave a comment