Advertisement
Guest User

Untitled

a guest
Dec 11th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. // #define N 3
  5. // don't use magic numbers
  6. // check the sumac, i guess the problem is there. Didn't tested
  7.  
  8. float sumac(float[3][], int);
  9. void arrange(float[3][], int, int);
  10.  
  11. int
  12. main(int argc, char* argv[])
  13. {
  14.     int i, j;
  15.     float x[3][3];
  16.    
  17.     for (i = 0; i < 3; i++)
  18.         for (j = 0; j < 3; j++)
  19.             cin >> x[i][j];
  20.  
  21.     for (j = 0; j < 3; j++)
  22.         for (i = 0; i < 3; i++) {
  23.             if (sumac(x, i) > sumac(x, i + 1))
  24.                 arrange(x, i, i + 1);
  25.         }
  26.    
  27.     for (i = 0; i < 3; i++) {
  28.         for (j = 0; j < 3; j++)
  29.             cout << x[i][j];
  30.             cout << endl;
  31.         }
  32.    
  33.     cin.ignore();
  34.     cin.get();
  35. }
  36.  
  37. float
  38. sumac(float x[3][3], int c)
  39. {
  40.    
  41.     float csum = 0;
  42.    
  43.     for (int i=0; i<3; i++)
  44.         csum += x[i][c];
  45.    
  46.     return csum;
  47. }
  48.  
  49. void
  50. arrange(float x[3][3], int r1, int r2)
  51. {
  52.     int j, temp = 0;
  53.    
  54.     for (j=0; j<3; j++) {
  55.         temp = x[r1][j];
  56.         x[r1][j] = x[r2][j];
  57.         x[r2][j] = temp;
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement