0

How can the factorial of any number be programmed in c++?

Code

6th Nov 2017, 4:54 PM
Boansi Kufuor Oliver
Boansi Kufuor Oliver - avatar
3 Answers
+ 14
#include <iostream> using namespace std; int main() { int num, factorial=1; cin>>num; for(int i=1;i<=num;i++) factorial=factorial*i; cout<<factorial; return 0; }
6th Nov 2017, 5:04 PM
Frost
Frost - avatar
+ 4
Here is the simplest solution: https://code.sololearn.com/ciGCbmm9BfTH/#cpp If you need an explanation, please tell me and I'll try to explain it. Also, you can do this with recursion.
6th Nov 2017, 5:06 PM
Maya
Maya - avatar
+ 4
This is the code with recursion: https://code.sololearn.com/cmfKDfPII6V6/#cpp
6th Nov 2017, 5:10 PM
Maya
Maya - avatar