Question #43137

1 - u + u^3/2! - u^5/3! + ... + (-1)^(2n-1) u^(2n-1)/n!

Expert's answer

`#include <iostream>`

#include <math.h>

#include <conio.h>

using namespace std;

int main(){

int n;

double u;

cout<<"n = ";

cin>>n;

cout<<"u = ";

cin>>u;

double sum = 1.0;

double value = u;

for (int i = 1; i <= n; ){

sum += pow(-1.0, (double)i)*value;

value *= u*u/(++i);

}

cout<<"answer = "<<sum<<endl;

getch();

return 0;

## Comments

## Leave a comment