I only want the answers to the QUESTIONS a & b. Please answer them corecctly in
ID: 3801464 • Letter: I
Question
I only want the answers to the QUESTIONS a & b. Please answer them corecctly in few sentences. Thank you.
Description: Write a C program that calculates the approximate value of from the following three infinite series: 3 7 9 11 TT- 12 4 9 16 25 36 (12)12 A1 3 3 3 A sample interaction and output of the program is given on a separate page. Your program should prompt the user for a non-negative integer and check its validity If the input is a negative integer, the program should display a message and prompt the user to input a non-negative integer again. All inputs are assumed to be of type integer. If the non-negative integer is zero, the program should terminate, otherwise it should output an approximate value of TT using the given series and prompt the user again. When writing the program, do not use the formula for the given series, simply write code that will alternately add or subtract a term to from the series. After completing and testing your program, answer the following questions and write your answer as comment at the end of your program. Questions: (a) How many terms of the above series do you have to use before you first get 3.14?, 3.141?, 3.1415?, or 3.14159? Make a table when answering this question. Each row should correspond to each given serie s and each column should correspond to the above given approximation. (b) Which series converges faster? Briefly explain.Explanation / Answer
CODE:
#include<stdio.h>
#include<math.h>
#define pi 3.1415
int piSeries1Count(double err) {
double sum = 0;
int x = 1;
int count = 0;
int k = 1;
while (fabs(sum - pi) > err) {
sum = sum + 4.0/x*k;
x = x + 2;
count ++;
k = k *-1;
}
printf("Series 1: pi = %lf, count = %d ",sum,count);
}
int piSeries2Count(double err) {
double sum = 0;
int x = 1;
int count = 0;
int k =1;
while (fabs(sum*sqrt(12) - pi) > err) {
sum = sum + 1.0/(x*pow(3,count))*k;
count ++;
x = x + 2;
k = k*-1;
}
printf("Series 2: pi = %lf, count = %d ",sum*sqrt(12),count);
}
void main() {
piSeries1Count(0.005);
piSeries2Count(0.005);
piSeries1Count(0.0005);
piSeries2Count(0.0005);
piSeries1Count(0.00005);
piSeries2Count(0.00005);
}
Series 1: pi = 3.136542, count = 198
Series 2: pi = 3.137853, count = 4
Series 1: pi = 3.141000, count = 1688
Series 2: pi = 3.141309, count = 6
Series 1: pi = 3.141450, count = 7010
Series 2: pi = 3.141569, count = 8
Series two converges much faster since the approximation of series 2 is much more appropiate since it consider suared values of pi for approximation