76 248
Assignments Done
98,5%
Successfully Done
In May 2019

# Answer to Question #37187 in C++ for aisha

Question #37187
Write a program to solve the following equation
Y=1/2!-2/3!+3/4!-4/5!+….n/(n+1)!
Where n is entered by the user. For example if user enters 3 then your program should calculate Y as 1/2!-2/3!+3/4!
Expert's answer
``#include <iostream>using namespace std;int main(int argc, char const *argv []) {       int     n,                      fact    = 1;   double  out     = 0;    cout << "Input n: "; cin >> n;    for(int i = 1, j = 2; i <= n; i++, j++)    {            double temp = i;        fact *= j;                temp /= fact;        if (i%2 == 0)                         out -= temp;                else                         out += temp;     }    cout << "Result: " << out << endl;    return 0; }``

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

#### Comments

No comments. Be first!

Submit