Program to find the factorial of any number ?

Factorial:

The factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n
6 fact=6*5*4*3*2*1
         =720
                                       


#include <iostream>
using namespace std;
int main()
{
int iteration,number,i,x=1;
char ch;
while(x!=0)
    {
    cout<<"Enter a number to find its factorial:"<<"\n";
    cin>>number;
        cin.get(ch);
        if(cin.fail())
        {
        cout<<"you enter data is not valid for factorial"<<"\n";
        break;
    }
    else if(ch=='.')
        {
            cout << "your enter data is not valid for factorial " <<"\n";
            break;
        }
    else
    {
    cout<<"Factorial of "<<number<<"=";
    int fact=1;
    for(int i=1; i<=number; i++)
        {
         
    fact=fact*i;
        }
        cout<<fact;
}
cout<<"\n\npress 0 for exit or press 1  to continue:"<<"\n";
cin>>x;
    } 
return 0;  







Above code output:


Comments