Advertisement
nguyenhappy92

1/2^2 -1/4^2 - .. + (-1) ^n-1/ (2*n)^2

Oct 22nd, 2015
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. // tinh 1/2^2 -1/4^2 - .. + (-1) ^n-1/ (2*n)^2
  2. // Khai bao cac ham thu vien neu co
  3. #include<stdio.h>
  4. #include<conio.h>
  5.  
  6. void main()
  7. {
  8. int n;
  9. scanf("%d",&n); // Nhap n
  10. long T=1;
  11. float s=0;
  12. for(int i=2;i<=n;i+=2) // i+=2 tuc la i=i+2 tang len 2 don vi
  13. {
  14. if((i/2)%2==0)// chia het cho 2
  15. {
  16. T=T*2*i*2*i;
  17. s=s-(float)1/T;
  18. }
  19. else// so ko chia het
  20. {
  21. T=T*2*i*2*i;
  22. s=s+(float)1/T;
  23. }
  24. }
  25. printf("%.3f",s);
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement