Advertisement
thien

BÀI 18

Mar 2nd, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. BÀI 18:
  2.  
  3. #include <conio.h>
  4. #include <stdio.h>
  5.  
  6. float tong(float a)
  7. {
  8. float i;
  9. float tong=1, dau=(-1);
  10. for (i=1; i<=a; i++)
  11. {
  12. tong=tong+dau*1/(2*i+1);
  13. dau=dau*(-1);
  14. }
  15. return tong;
  16. }
  17. main()
  18. {
  19. float c;
  20. float n=0, pi;
  21. printf(" Nhap vao so c la: ");
  22. scanf("%f", &c);
  23. while (1>((2*n+1)*c))
  24. {
  25. n++;
  26. }
  27. pi=4*tong(n);
  28. printf(" Gia tri so pi la: %f\n", pi);
  29. getch();
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement