Advertisement
nguyenhappy92

Tính tổng các giá trị lớn hơn trị tuyệt đối

Dec 24th, 2015
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. // Tinh gia tri tuyet doi lien sau mang so thuc
  2. // Khai bao cac ham thu vien neu co
  3. #include<stdio.h>
  4. #include<conio.h>
  5. #include<math.h>
  6. #define SIZE 100
  7. void nhap(float a[],int &n)
  8. {
  9. scanf("%d",&n);
  10. float x;
  11. for(int i=0;i<n;i++)
  12. {
  13. scanf("%f",&x);
  14. a[i]=x;
  15. }
  16. }
  17. double tongliensau(float a[],int n)
  18. {
  19. double s=0;
  20. for(int i=0;i<n;i++)
  21. {
  22. if(a[i]>fabs(a[i+1]))// gia tri tuyet doi cho so thuc fabs
  23. {
  24. s=s+a[i];
  25. }
  26. }
  27. return s;
  28. }
  29. void main()
  30. {
  31. float a[SIZE];
  32. int n;
  33. nhap(a,n);
  34. printf("%.2lf",tongliensau(a,n));
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement