+ 1
factorial
why it's not give a right outbut when i inbut both negative value or zero #include<iostream> using namespace std; int main(){ cout <<"please enter a postive number to calculate the factorial of it\n"; int fact,x; cin>>x; fact=x; if(x>1){ while(x>1) { x--; fact=fact*x; } cout<<"the factorial value is "<<fact<<"\n";} else if (x=1||x=0) cout<<"the factorial value is 1\n"; else cout<<"please enter a postive number only"; return 0; }
4 ответов
+ 1
Yes. It is
0
Hi bro. I have fixed all the bugs, now it is working like a charm. If you have any questions regarding the code,feel free to keep in touch with me.
#include<iostream>
using namespace std;
int main(){
cout <<"please enter a postive number to calculate the factorial of it\n";
int fact=1,x;
cin>>x;
fact=x;
if(x>1){
while(x>1)
{
x--;
fact=fact*x;
}
cout<<"the factorial value is "<<fact<<";\n";
}
else if (x==1 || x==0)
cout<<"the factorial value is 1\n";
else
cout<<"please enter a postive number only";
return 0;
}
0
This is the answer based on your previous question which i think delete alreade. However, it is working ,now you can change some other parts and practise. Have a fun. :-)))
0
thank you and this is the final correct code
#include<iostream>
using namespace std;
int main(){
cout <<"please enter a postive number to calculate the factorial of it\n";
int fact,x;
cin>>x;
fact=x;
if(x>1){
while(x>1)
{
x--;
fact=fact*x;
}
cout<<"the factorial value is "<<fact<<"\n";}
else if (x==1||x==0)
cout<<"the factorial value is 1\n";
else
cout<<"please enter a postive number only";
return 0;
}