There are many formulas in the history of Pi Pai, in which Gregory and Leibniz found the following formula:
Pai = 1-1/3+1/5-1/7 (...)
This formula is simple and graceful, but in the ointment, it converges too slowly.
If we rounded up the two decimal places that kept it, then:
Accumulated 1 Items and yes: 4.00
Accumulated 2 Items and yes: 2.67
Accumulated 3 items and yes: 3.47
。。。
Please write down how much it accumulates 100 items (rounded up to two decimal places).
Source:
#include <stdio.h>//pai = 1-1/3+1/5-1/7 (...) Double while () {double sum=0;int flag=1;//odd entry bit positive, even entry is negative double temp=1;int i=1;while (i<=100) {temp=1.0/(2*i-1) * (flag); I++;sum=sum+temp;flag=-flag;} return sum; }int Main () {double pai=0.0;pai=4*while ();p rintf ("%.8lf\n", Pai); return 0;}
Output: 3.13159290, so rounded to 3.13
Formula for calculating pi pai: Pai = the 1-1/3+1/5-1/7 (...)