Sunday, August 2, 2009

Write a c++ code for an integer that displays the factorial of that number.?

int factorial (int num)


{


if (num==1)


return 1;


return factorial(num-1)*num; // recursive call


}








OR








#include %26lt;iostream.h%26gt;





int factorial(int);





void main(void) {


int number;





cout %26lt;%26lt; "Please enter a positive integer: ";


cin %26gt;%26gt; number;


if (number %26lt; 0)


cout %26lt;%26lt; "That is not a positive integer.\n";


else


cout %26lt;%26lt; number %26lt;%26lt; " factorial is: " %26lt;%26lt; factorial(number) %26lt;%26lt; endl;


}





int factorial(int number) {


int temp;





if(number %26lt;= 1) return 1;





temp = number * factorial(number - 1);


return temp;


}

Write a c++ code for an integer that displays the factorial of that number.?
Do your own homework.

poppy

No comments:

Post a Comment