2. Calculate the value of ? from the infinite series ?=4--+ +--… 3 579 , 1500 te
ID: 3901881 • Letter: 2
Question
2. Calculate the value of ? from the infinite series ?=4--+ +--… 3 579 , 1500 terms of Print a table that shows the approximate value of ? for 100, 200, 300, 400 the series Expected Output pi with 100 terms = 3.131592903558552 pi with 200 terms 3.136592684838814 pi with 300 terms 3.138259329515588 pi with 400 terms 3.139092657496011 pi with 500 terms 3.139592655589782 pi with 600 terms 3.139925988080528 pi with 700 terms 3.140164082890081 pi with 800 terms 3.140342654078072 pi with 900 terms 3.140481542821614 pi with 1000 terms 3.140592653839790 pi with 1100 terms 3.140683562868528 pi with 1200 terms3.140759320401133 pi with 1300 terms 3.140823422934350 pi with 1400 terms 3.140878367966611 pi with 1500 terms 3.140925986997196Explanation / Answer
The table will be and code will be
#include <stdio.h>
double calc(int n)
{
int i;
int sign=1;
double sum=0;
for(i=1;i<=n;i++)
{
sum+=(sign*4)/(double)(2*i-1);
sign=-sign;
}
return sum;
}
int main()
{
int i=100;
for(i=100;i<=1500;i+=100)
{
printf("pi with %d terms = %.15lf ",i,calc(i));
}
}
The output is
pi with 100 terms = 3.131592903558554
pi with 200 terms = 3.136592684838816
pi with 300 terms = 3.138259329515591
pi with 400 terms = 3.139092657496014
pi with 500 terms = 3.139592655589785
pi with 600 terms = 3.139925988080531
pi with 700 terms = 3.140164082890085
pi with 800 terms = 3.140342654078076
pi with 900 terms = 3.140481542821618
pi with 1000 terms = 3.140592653839794
pi with 1100 terms = 3.140683562868532
pi with 1200 terms = 3.140759320401137
pi with 1300 terms = 3.140823422934354
pi with 1400 terms = 3.140878367966614
pi with 1500 terms = 3.140925986997199
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.