Advertisement
nguyenhappy92

Tinh S(n) = 1^2 + 2^2 + 3^2 + ... + n^2

Sep 15th, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.27 KB | None | 0 0
  1. //Tinh S(n) = 1^2 + 2^2 + 3^2 + ... + n^2
  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 cua bien
  11. scanf("%d",&n);
  12. long s=0;
  13. for(int i=0;i<=n;i++)
  14. {
  15. s=s+ (i*i);
  16. }
  17. printf("%ld",s);
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement