0

with the formula : Result = 1+2!/((x-2))-3!/((x-3))+4!/((x-4) )- n!/((x-n))

i want the output as :

Please key in x value: 8

Please key in n value: 5

## result = 1 +2!/6-3!/5+4!/4-5!/3 = -33.8667

i have done the code , still cannot get the output , can anyone help me to check where the problem???

```
#include<iostream>
using namespace std;
int fact (int no)
{
int total;
for (int i=0; i<=no; i++)
{
if(i ==0)
total = 1;
else
total = total * i;
}
return total;
}
int main()
{
int x,n;
double result;
cout<<"Please key i x value : ";
cin>>x;
cout<<"\n";
cout<<"Please key in n value : ";
cin>>n;
if (x<n)
cout<<"Wrong input, x valur must be greater than n !!\n"<<endl;
else
cout <<"\nResult = 1 +2!/"<<x-2
<<" - 3!/"<<x-3
<<" + 4!/"<<x-4<< " - "<<n
<<"!/"<<x-n
<<" = "<<1+(fact(2)/x-2)-(fact(3)/x-3)+(fact(4)/x-4)-(fact(n)/x-n);
system("pause");
return 0;
}
```