Advertisement
nguyenhappy92

Bài tập Tính S(n) = 1 + 2 + 3 + ... + n

Sep 15th, 2015
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. // Tinh S(n) = 1+2+3+...+n
  2. // Khai bao thu vien
  3. #include<stdio.h>
  4. #include<conio.h>
  5.  
  6. void main()
  7. {
  8. // khai bao bien n
  9. int n;
  10. //nhap gia tri n
  11. scanf("%d",&n);
  12. //khai bao gia tri S
  13. long s=0;
  14. for(int i=0;i<=n;i++)
  15. {
  16. s=s+i;//Tinh S
  17. }
  18. // Xuat gia tri da tinh duoc
  19. printf("%ld\n",s);
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement