Skip to content
site-logo
  • Home
  • JavaScript
  • Machine Learning
  • C++Expand
    • C++ Programing
    • Numerical Techniques C++
    • Data Structures C++
    • C++ Programs
  • Typing Guide
  • Blogs
site-logo
Home / C++ Programs / C++ Program To Calculate Factorial of a Number Using Recursion

C++ Program To Calculate Factorial of a Number Using Recursion

ByLonz Updated onSeptember 24, 2021
C++ Programs
Ad

The factorial of a positive number is the product of all the integer numbers from 1 up to that particular number say n.

Let us take an example, the factorial of a number 5 is the product of all numbers from 1 to the number itself as 1*2*3*4*5 = 120.

Ad

Factorial can be defined for Positive Intergers only.

There is no factorial of Negative numbers.

The factorial of 0 is 1.

C++ Program of Factorial 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;
}
Code language: PHP (php)

Output Of Above Program

Enter an positive integer: 6
Factorial of 6 = 720

Post navigation

Previous Previous
C++ Program To Find Factorial Of A Number N
NextContinue
C++ Program to Check Whether a Number is Prime or Not
Search

  • Home
  • Privacy Policy
  • Disclaimer
  • Sitemap
  • Write for us
  • Contact Us

Copyright © 2025 TechInDetail

Scroll to top
  • Home
  • JavaScript
  • Machine Learning
  • C++
    • C++ Programing
    • Numerical Techniques C++
    • Data Structures C++
    • C++ Programs
  • Typing Guide
  • Blogs
Search