PROGRAM TO CALCULATE FACTORIAL OF A NUMBER

/*PROGRAM TO CALCULATE FACTORIAL OF A NUMBER*/

#include<conio.h>

#include<iostream.h>

class factorial

{

int f,n,i;

public:

void input();

void output();

};

void factorial::input()

{

cout<<“Enter any positive number: “;

cin>>n;

}

void factorial::output()

{

if(n>0)

{

f=1;

for(i=n;i>=1;i–)

f=f*i;

cout<<“Factorial of “<<n<<” is: “<<f;

}

else

cout<<“Number must be greater than 1″;

}

void main()

{

factorial f1;

clrscr();

f1.input();

f1.output();

getch();

}

Leave a Reply

Your email address will not be published. Required fields are marked *