Advertisement
nguyenhappy92

tính tổng bình phương của các số âm trong một mảng

Oct 16th, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. // Tinh tong binh phuong cac so am trong mang
  2. // Khai bao thu vien neus cos
  3.  
  4. #include<stdio.h>
  5. #include<conio.h>
  6. #define SIZE 100
  7. void nhap(int A[],int &n);
  8. long tongbinh(int A[],int n);
  9. void main()
  10. {
  11. int A[SIZE],n;
  12. nhap(A,n);
  13. printf("%ld",tongbinh(A,n));
  14. }
  15. void nhap(int A[],int &n)
  16. {
  17. scanf("%d",&n);
  18. for(int i=0;i<n;i++)
  19. {
  20. scanf("%d",&A[i]);
  21. }
  22. }
  23. long tongbinh(int A[],int n)
  24. {
  25. long s=0;
  26. for(int i=0;i<n;i++)
  27. {
  28. if(A[i]<0)
  29. {
  30. s=s+ (A[i]*A[i]);
  31. }
  32. }
  33. return s;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement