+ 1
write a program to obtain the value of π π=4-4/3+4/5-4/7+4/9-.......
2 odpowiedzi
+ 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;
}
+ 1
if you select a smaller number to exit while loop, precision of output will be lesser.