+ 5
Can anyone help me.
This code is not giving the output that I want. https://code.sololearn.com/cQZnF853mqRG/?ref=app
4 ответов
+ 5
You shouldn't output a, but f.
+ 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
+ 1
This is not a factorial calculation. Factorial is calculated using recursion. In addition, the program does not cut negative numbers and zero.
+ 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;
}