Advertisement
nguyenhappy92

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

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