write a program to obtain the value of π π=4-4/3+4/5-4/7+4/9-....... | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

write a program to obtain the value of π π=4-4/3+4/5-4/7+4/9-.......

22nd Sep 2016, 2:13 AM
Meena
Meena - avatar
2 Answers
+ 3
#include <iostream> using namespace std; int main() { double pi=0; int sign = 1; double counter=1; while(counter <10000) { pi += sign*4.0/counter; counter += 2; sign *= -1; } cout<< "value of pi is "<<pi; return 0; }
23rd Sep 2016, 4:14 PM
Zaman
Zaman - avatar
+ 1
if you select a smaller number to exit while loop, precision of output will be lesser.
23rd Sep 2016, 4:16 PM
Zaman
Zaman - avatar