Tuesday 26 November 2013

C++ : Factorial of a Number

Factorial of a Number :

Here is the code for the Factorial of a number in C++ code :

#include<iostream>
using namespace std;
int main()
{
    int num,factorial=1;
    cout<<" Enter Number To Find Its Factorial:  ";
    cin>>num;
    for(int a=1;a<=num;a++)
    {
        factorial=factorial*a;
    }
cout<<"Factorial of Given Number is ="<<factorial<<endl;
    return 0;
}
  

Output :

Enter Number To Find Its Factorial: 3

0! = 1
1! = 1
2! = 2
3! = 6


No comments:

Post a Comment