fork(1) download
  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <iostream>
  4. #include <cmath>
  5.  
  6. using namespace std;
  7.  
  8. #define PI 3.14159265
  9.  
  10. double integrate(double x1, double x2, double r)
  11. {
  12. double r1 = (std::sqrt(r*r - x1*x1)/2 * x1 + (9*asin(x1/3))/2);
  13. double r2 = (std::sqrt(r*r - x2*x2)/2 * x2 + (9*asin(x2/3))/2);
  14.  
  15. return 4 * (r2 - r1);
  16. }
  17.  
  18. void calculate(double radius)
  19. {
  20. double Result = integrate(0, radius, radius);//((9.0/4.0) + (sqrt(6) / 2.747319)) * radius * radius;
  21. double realResult = PI * radius * radius;
  22.  
  23. printf("The area of the circle with radius %lf is %lf.\n",radius,Result);
  24. printf("The real area of the circle is %lf.",realResult);
  25. cout << endl;
  26. }
  27.  
  28. int main(int nNumberofArgs,char* pszArgs[])
  29. {
  30. double radius;
  31. cout << "Enter radius: ";
  32. cin >> radius;
  33.  
  34. calculate(radius);
  35.  
  36. //system("PAUSE");
  37. return 0;
  38. }
Success #stdin #stdout 0s 2988KB
stdin
3
stdout
Enter radius: The area of the circle with radius 3.000000 is 28.274334.
The real area of the circle is 28.274334.