+ 5

Can anyone help me.

This code is not giving the output that I want. https://code.sololearn.com/cQZnF853mqRG/?ref=app

18th Jul 2019, 8:16 AM
Muaz Ahmad
Muaz Ahmad - avatar
4 ответов
+ 5
You shouldn't output a, but f.
18th Jul 2019, 8:18 AM
Airree
Airree - avatar
+ 2
Сергій Гавриленко I don't think he wanted to make a perfect factorial calculator, and you can calculate the factorial of the number with loops too
19th Jul 2019, 1:43 PM
Airree
Airree - avatar
+ 1
This is not a factorial calculation. Factorial is calculated using recursion. In addition, the program does not cut negative numbers and zero.
19th Jul 2019, 1:41 PM
Сергій Гавриленко
Сергій Гавриленко - avatar
+ 1
#include <iostream> using namespace std; int main() { int a,f,n; f=1; cin>>n; if (n==0) cout<<'1'; else if (n<0) cout<<"No factorial for negative numbers."; else { for(a=1;a<=n;a++){ f*=a;} cout <<f;} return 0; }
19th Jul 2019, 3:12 PM
Сергій Гавриленко
Сергій Гавриленко - avatar