Loading...

Factorial_Without_Recursion


/*/////////////////////////////////////////////////////////////////////////////
 * Factorial without using recursion
 * Shubham Kumar
 * sshubhamk1@hotmail.com
/////////////////////////////////////////////////////////////////////////////*/

#include <iostream>
using namespace std;
long fact(int num);
int main(void)
{
    int num;
    do
    {
        cout <<"Enter the number: ";
        cin >> num;
        if(num <0)
        {
            cout << "Number should be non-negative. Try agian..."<<endl;
        }
    }while(num <0);
    cout << "The Factorial of "<< num << " is "<< fact(num) << endl;
    return 0;
}
long fact(int num)
{
    long result = 1;
    for(int i = 2;i <= num;i++)
        result *= i;
    return result;
}


123 Sample Rd, Samplington, SA 12345
(555) 0123