mathematical question

This is the formula for the equation....

Result = 1+ 2!/((x-2))-3!/((x-3))+4!/((x-4) )- … n!/((x-n))

can anyone tell me how to create this program....??
i dont know how to compile it in c++..help me pls
How would you solve it on paper?
^ And that is how you can solve any math problem with c++
Really? I rate C++ akin to a graphing calculator. If you know the features, you can cut out most of the hard work. lol
ResidentBiscuit:yes i have to write the coding on a paper.

the program should ask the user to input 1 integer ....
example the user enters x=3 and n=2
the program will run and print out the answer..
my friends told me that i have to use a for loop and also selection statements..
No Warrenty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>

using namespace std;

// n!
double f(double x)
{
    if(x > 1)
        return x * f(x - 1);

    return 1;
}

// n!/((x-n))
double fn(double x, double n)
{
    return f(n) / (x - n);
}

int main(int argc, char *argv[])
{
    double x = 0;
    double n = 0;
    double result = 1;

    cout << "Enter X = ", cin >> x;
    cout << "Enter N = ", cin >> n;

    // Result = 1+ 2!/((x-2))-3!/((x-3))+4!/((x-4) )- … n!/((x-n))
    for(int i = 2; i <= n; i++)
        if(i % 2)
            result -= fn(x, i);
        else
            result += fn(x, i);

    cout << "Result  = " << result << endl;
}
tq very much santosh reddy the code 100% works for me....i just need to know whats the double f and double fn...
I guess, that will be your homework :)
Topic archived. No new replies allowed.