Search & Find out

Sunday, December 6, 2009

FACTORIAL



 #include "iostream.h"
#include "conio.h"
class fac
{
    private:
        long n;
    public:
        void accept ()
        {
            cout << "Welcome to finding a factorial of a no.\n\n";
            cout << "Enter a number( 1 to 31): ";
            cin  >> n;
        }
        void cal ();
};
void fac :: cal ()
{
    cout << "\nFactorial of " << n << " is: ";
    for (int i=n-1; i>0; i--)
    {
        n *= i;
    }
    cout << n;
}
void main ()
{
    clrscr ();
    fac F;
    F.accept ();
    F.cal ();
getch ();
}



Get the executable ( .exe ) file for this program..
Download

0 comments:

Post a Comment

 

My Blog List

Term of Use