Welcome

Hi! This blog is for beginners of c++ and java .You can check and pick codes for your programming assignments. This will also help you to understand the concepts of these programming languages. Its all about programming.

Template Practice (Factorial Program)

Wednesday, May 25, 2011

#include<iostream>
using namespace std;
template<class T>
class fac
{
private:
  T a,f;
public:
 void getdata()
  {
  cout<<"\n Enter the number = ";
  cin>>a;
  }
void fact()
  {
   f=1;
   for (int i=a;i>0;i--)
   {
    f=f*i;
   }
   cout<<"Factorial is: " <<f;
  }
};
void main()
{
fac<int>s;
s.getdata();
s.fact();
}