Search This Blog

Thursday, 25 October 2012

Recursive Member Functions

#include<iostream.h>
class num{
public:
int fact(int n)
{
if(n==1 || n==0)
return 1;
else
return(n*fact(n-1));
}
};
void main()
{

num N;
N.fact(5);
}

Output:
120

No comments:

Post a Comment