Anyone who know what is the code that i have to write in to get the answer ?????
with the formula : 1+2!/((x-2))-3!/((x-3))+4!/((x-4)) - ... n!/((x-n))
#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()
{
double 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<<"Result = 1 + ";
for (int loop = 2; loop< x+1; loop++)
{
if (loop%2 ==0)
{
cout<<loop<<"!/"
<<x-loop;
if (loop == x)
{
cout<<" = ";
}else{
cout<<" - ";
}
}else{
cout<<loop<<"!/"
<<x-loop;
if (loop == x)
cout<<" = ";
else
cout<<" + ";
}
}
}
system("pause");
return 0;
}