Wednesday, October 30
Fatorial using For loop
In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example,
(for more info visit Factorial on Wiki )
Code:
(for more info visit Factorial on Wiki )
Code:
#includeusing namespace std; int main() { int factorial = 1, value = 1; cout << "Please enter value to find its factorial" << endl; cin >> value; int temporary = value; if (value < 0) { cout << "please enter a positive number "; main(); } else if (value<2) { cout << "factorial of " << value << " is " << 1 << endl; } else { for (; temporary>1; factorial *= temporary--); cout << "factorial of " << value << " is " << factorial << endl; return 0; } }
:D :D look at your names
ReplyDeletehmm...
ReplyDeleteI see what you did there :P
ReplyDeleteplease tell me where have you used for loop :P
ReplyDelete