please help me . I have one day
question: Finding pi through computing area of a quarter circle
my code
HOW can i fix it ?Code:#include <iostream> #include <cmath> #include <iomanip> using namespace std; int main() { double sum,PI,h,x=0; while (x<=2) { h=sqrt((2*2)-(x*x)); x=x+(2./20000.); sum=sum+h; } PI=sum*(1./10000.); cout << " Pi value is " <<setprecision(50)<<PI << system("pause"); }The program cannot precisely find the value of pi.
result is
expect value: 3.1415926535Code:3.14169223