Monday 7 April 2014

Find factorial of an number/integer in c++ using recursive function/function recursion .

C++ program  to print factorial of  numbers  ,given by users .The programme has been run successfully in VS (Visual studio) express 2013 and codeblocks and its working fine with no error .


#include<iostream>
using namespace std;
int fact(long int n);
int main()
{
long int i, j;
cout << "enter the no : ";
cin >> i;
if (i<0){ cout << "that is not positive"; };
j = fact(i);
cout << "factorial of :" <<i<<" is "<< j<<endl;

return 0;
}

int fact(long int n)
{
int f;
if (n <= 1) return 1;
f = n*fact(n - 1);
return (f);




}




output:


enter the no : 10
factorial of :10 is 3628800
Press any key to continue . . .


No comments:

Post a Comment