C++ Online Compiler
Example: C++ program to find factorial of a number using recursion
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// C++ program to find factorial of a number using recursion #include <bits/stdc++.h> using namespace std; // @recursive function to find the factorial long int RecursiveFacto(int fact_number) { if (fact_number >= 1) return fact_number * RecursiveFacto(fact_number - 1); else return 1; } // @driver function to call & find // @factorial of a number using recursion int main() { int fact_number = 0; cout << "Enter a positive integer number: "; cin >> fact_number; // It will call the RecursiveFacto() function cout << "\nFactorial of " << fact_number << " is: " << RecursiveFacto(fact_number) << endl; return 0; }
7
Output
Clear
ADVERTISEMENTS