Write a C++ program to Calculate Factorial of a Number Using Recursion

C++ program to Calculate Factorial of a Number Using Recursion

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn C++ programming concepts. You can learn C++ language at your own speed and time. One can learn concepts of C++ language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

C++ program to Calculate Factorial of a Number Using Recursion
C++ program to Calculate Factorial of a Number Using Recursion

Write a C++ program to Calculate Factorial of a Number Using Recursion

PROGRAM:C++ program to Calculate Factorial of a Number Using Recursion

/* C++ program to Calculate Factorial of a Number Using Recursion*/

#include<iostream>
using namespace std;

int factorial(int n);

int main() {

int n;

cout << “Enter a positive integer: “;
cin >> n;

cout << “Factorial of ” << n << ” = ” << factorial(n);

return 0;
}

int factorial(int n) {
if(n > 1)
return n * factorial(n – 1);
else
return 1;
}

Leave a Reply

Your email address will not be published. Required fields are marked *