Learn Object Oriented Programming (OOP) in C++ / সি++ Here
#includeusing namespace std;class recursive{ public: int rec(int x){ if(x<=1) return 1; else return(x*rec(x-1));}};int main(){ recursive rc; int a; cin>>a; cout<<"the factorial is: "<<rc.rec(a);}
Noted. Found correct. It is quite appreciable that you did it using recursive with class.
#includeusing namespace std;int fact(int n); int main() { int n,result=0; cin>>n; cout<<"the factorial is:"<<fact(n); }int fact(int inp) { if(inp<=1) return 1; else return(inp*fact(inp-1)); }
noted
Dear Sir, Please visit:http://itlearn24.blogspot.com/2014/11/recursive-function-progamming.html
noted.
#includeusing namespace std;int fact(int r);int main(){int r;cin>>r;cout<< "The factorial is:"<<fact(r);return 0;}int fact(int r){if(r!=1) return r*fact(r-1);}
Comment Here
#include
ReplyDeleteusing namespace std;
class recursive
{
public:
int rec(int x)
{
if(x<=1)
return 1;
else
return(x*rec(x-1));
}
};
int main()
{
recursive rc;
int a;
cin>>a;
cout<<"the factorial is: "<<rc.rec(a);
}
Noted. Found correct. It is quite appreciable that you did it using recursive with class.
ReplyDelete#include
ReplyDeleteusing namespace std;
int fact(int n);
int main()
{
int n,result=0;
cin>>n;
cout<<"the factorial is:"<<fact(n);
}
int fact(int inp)
{
if(inp<=1)
return 1;
else
return(inp*fact(inp-1));
}
noted
DeleteDear Sir, Please visit:
ReplyDeletehttp://itlearn24.blogspot.com/2014/11/recursive-function-progamming.html
noted.
Delete#include
ReplyDeleteusing namespace std;
int fact(int r);
int main()
{
int r;
cin>>r;
cout<< "The factorial is:"<<fact(r);
return 0;
}
int fact(int r)
{
if(r!=1)
return r*fact(r-1);
}