RenHao

HW6_PI

Aug 23rd, 2014
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.41 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  5. // x^2 + y^2 = 1
  6. double y(double x)
  7. {
  8.     return  sqrt(1 - pow(x,2)) ;
  9. }
  10.  
  11. int main(int argc, char *argv[])
  12. {
  13.     double i,A=0 ;
  14.    
  15.     for(i=-1;i<0 ; i = i+0.1)
  16.     {
  17.         A += (y(i+0.1)-y(i)) * 0.1 ;
  18.     }
  19.     A = A * 4 ;
  20.     printf("%.5f\n",A);
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment