Advertisement
nguyenhappy92

Tính tổng dương trong ma trân 2 chiều số thực

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