C++ gurus and learners, we program ourselves :P all work is CC licensed

Saturday, November 9

Factorial Using Recursive Function

20:56 By

#include <iostream>
#include <conio.h>

using namespace std;



int Factorial(int number)
{
 if (number <2)
 {
  return 1;
 }
 else
 {
  return (number * Factorial(number - 1));
 }
}

void main()
{
 int num;
 cout << "Enter Number: ";
 cin  >> num;

 int fact = Factorial(num);
 cout << "\nFactorial: " << fact;

 _getch(); //use 'getch()' if you are using version older than Visual Studio 2013.
}

4 comments :

  1. sir what is difference between getch and _getch ?

    ReplyDelete
  2. Good Blog But Sir It is Giving error in my IDE "Code Blocks " Which is
    error: stray '\240' in program twenty times ,,,,,

    ReplyDelete
  3. This means there was error in copying the code from here, try using double quotes of browser

    ReplyDelete