Advertisement
nguyenhappy92

Tính S(n) = 1 + 1/(1+2) + 1/(1+2+3) + ... + 1/(1+2+3+⋯+n)

Sep 18th, 2015
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.31 KB | None | 0 0
  1. //Tính S(n) = 1 + 1/(1+2) + 1/(1+2+3) + ... + 1/(1+2+3+..+n)
  2. // Khai bao ham thu vien
  3. #include<stdio.h>
  4. #include<conio.h>
  5.  
  6. void main()
  7. {
  8. // khai bao bien
  9. int n;
  10. // Nhap du lieu
  11. scanf("%d",&n);
  12. long T=0;
  13. float M=0;
  14. for(int i=1;i<=n;i++)
  15. {
  16. T=T+i;
  17. M=M+ (float)1/T;
  18. }
  19. printf("%.2f",M);
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement