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!
1
Expert's answer
2017-03-27T11:34:30-0400
#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 the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS