The program is calculating the factorial of a number using recursion. The factorial function takes an integer n as input and returns its factorial. If n is greater than 1, the function calls itself with n-1 as input and multiplies the result with n to get the factorial of n. If n is 1 or less, it returns 1, which is the factorial of 0 and 1. In the main function, it takes the input number from the user, calls the factorial function to calculate its factorial, and displays the result
#include <iostream> using namespace std; int factorial(int); int main() { int n,result; cout<<"Enter a number: "; cin>>n; result=factorial(n); cout<<"Factorial of "<<n<<" = "<<result; return 0; } int factorial(int n) { if(n>1) { return n*factorial(n-1); } else { return 1; } }To download raw file Click Here
Enter a number: 10 Factorial of 10 = 3628800
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions