0
How can the factorial of any number be programmed in c++?
Code
3 odpowiedzi
+ 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;
}
+ 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.
+ 4
This is the code with recursion: https://code.sololearn.com/cmfKDfPII6V6/#cpp