Saturday, 28 March 2015

How to Print Factorial Number in C++


// Problem : Calculate factorial of a given number using C++

#include<iostream>
using namespace std;
int main()
{
   long num;
   int j=1;
   long fact=1;
   cout << "Enter the number for Factorial......... : ";
   cin >> num;
   cout << endl;
   if(num==0)
   {
   cout << j;         
   }   
   else
   {
     for(int i=num;i>0;i--)
     {
       fact *= i;                 
     } 
     cout << num << "! = " << fact << endl;
   }
   cout << endl;
   system("pause");
   return 0;
}

0 comments:

Post a Comment