Ask a Teacher



write a c++ program to find factorial of any number using class function.

#include<iostream.h>
#include<conio.h>
class factorial
{
int num;
public:
void getinfo()
{
cout<<"\n Enter the number for which the factorial is to be found : ";

cin>>num;
}
void facto()
{
int i,fact=1;
if(num==0||num==1)
cout<<"\n Factorial of "<< num<<”is”<< num;

else
{
for(i=1;i<=num;i++)
{fact=fact*i;
}
cout<<"\n Factorial of "<< num<<”is”<< fact;

}
}
};
void main()
{
factorial f1;
clrscr();
f1.getinfo();
f1.facto();
getch();
}





comments powered by Disqus