Write c++ program to create class factorial and find factorial of given number

//Note: If you are not using Borland or Turbo C then add the following line after header files :
//using namespace std;

#include<conio.h>
#include<iostream.h>
class factorial
{
        int n;
        public:
int fact(n)
{
        if(n<=0)
                  return 1;
            else
                return n*fact(n-1); // recursion
}
};
int main()
{
   factorial obj; // object created
   int n,f;
   cout<<"Enter how many elements:";
   cin>>n;
   cout<<"The factorial of "<<n<<" is: "<<obj.fact(n);
   getch();
   return(0);
}

0 Comments