- Messages
- 15
- Reaction score
- 0
- Points
- 0
this refers to the following question:"You are required to design a complete system which will allow you to calculate the factorial of n, a value which is specified by the user."
SOL:
//Programme to output factorials
#include <iostream>
using namespace std;
int main ()
{
int fct,fctval; //fct is the value whose factorial we need, and fctval is the factorial
cout<< "Please enter value:";
cin>> fct;
while (fct>0){
fctval=fct*(--fct);
--fct;
}
cout<<fctval;
return 0;
}
wenever i enter a value, the output is 1. CAn u pls tell me wat im doing wrong here?
SOL:
//Programme to output factorials
#include <iostream>
using namespace std;
int main ()
{
int fct,fctval; //fct is the value whose factorial we need, and fctval is the factorial
cout<< "Please enter value:";
cin>> fct;
while (fct>0){
fctval=fct*(--fct);
--fct;
}
cout<<fctval;
return 0;
}
wenever i enter a value, the output is 1. CAn u pls tell me wat im doing wrong here?