Skip to content
site-logo
  • Home
  • Blog
  • JavaScript
  • Machine Learning
  • Numerical Techniques C++
  • Data Structures C++
  • Typing Guide
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

Ad

Categories

  • C++ Programing
  • C++ Programs
  • Computer Graphics
  • Data Structures C++
  • JavaScript
  • Machine Learning
  • Numerical Techniques C++
  • Processor
  • Tech Updates
  • Typing Guide
  • Un Categorised

Recent Posts

  • NetSuite Cloud ERP Features
  • Is i7 Better Than i5
  • setTimeout vs setInterval JavaScript Methods
  • String Formatting In JavaScript

Ad


  • Home
  • Blog
  • Privacy Policy
  • Disclaimer
  • Sitemap

Copyright © 2023 Tech In Detail

  • Home
  • Blog
  • JavaScript
  • Machine Learning
  • Numerical Techniques C++
  • Data Structures C++
  • Typing Guide
Search