please answer................. using switch statement.write a menu driven program for the following...
1) to find and display the sum of the following .............
s= x¹/1-x²/2!-x³/3!+x⁴/4!--------------x^n/n!................
please solve it ....spammers will be reported..........
Answers
Answered by
1
Answer:
// C++ program to find sum of series
// 1 + x/1 + x^2/2 + x^3/3 + ....+ x^n/n
#include <math.h>
#include <iostream>
#include <boost/format.hpp>
class gfg
{
public :
double sum(int x, int n)
{
double i, total = 1.0;
for (i = 1; i <= n; i++)
total = total +
(pow(x, i) / i);
return total;
}
};
// Driver code
int main()
{
gfg g;
int x = 2;
int n = 5;
//std::cout<<g.sum(x,n);
std::cout << boost::format("%.2f") % g.sum(x,n);
return 0;
}
Similar questions