/**
This is a common factorial function using recursive.
Compiled with Dev C++ 4.9.9.2
Swiss German University
ICT – 2
*/
#include <iostream>
using namespace std;
// Function Prototype
long factorial( long );
int main() {
cout << ” The result is come from N! = (N-1)*(N-2)*…*(N equal 1) “ << endl;
for(int i = 0; i <= 10; i++ ) {
cout << i << “! = “;
cout << factorial(i) << endl;
}
system(“pause”);
return 0;
}// end of main function
/**
@param long – number
A “n” factorial number.
@return
If the number is 1 or less than 1 return 1.
Otherwise, it will be return a result
*/
long factorial( long number ) {
if( number <= 1 )
return 1;
else //Recursive
return ( number * factorial( number – 1 ) );
}// end of factorial function

No comments yet
Comments feed for this article