Write C code that does the following: 1. Numerically compute the following series 1−13+15−17+..=????4 and approximate π. Vary iteration numbers. Note that the general term, an, is expressed as ????????=(−1)????+12????−1

Respuesta :

Answer:

Explanation:

See attachment for the screen shot of the code.

//Sample Output

nter the numberof iterations4 The sum of the series is0.723810

//Code to copy

#include<stdio.h>

int main()

{

// Declare and initialize the Variables

int i, n;

int sign_flag = 1;

double sum = 0.0;

// Taking the number of iteration as input

printf("Enter the number of iterations ");

scanf("%d", &n);

// Sum upto n terms

// Sign flag is used for alternate positive and negative terms

for (i = 1; i <= n; i++)

{

sum = sum + sign_flag*(1.0 / (2 * i - 1));

sign_flag = -sign_flag;

}

// Print the sum

printf("The sum of the series is %lf\n", sum);

return 0;

}

Ver imagen dammymakins