Advertisement
Guest User

Part2-3

a guest
Mar 5th, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. //Written by Oles Bober
  2. #include <iostream>
  3. #include <sstream>
  4.  
  5. using namespace std;
  6.  
  7. const int SIZE = 3;
  8.  
  9. void sortColumns (const double decList[][SIZE], double tempArray[][SIZE];) {
  10.     for (int i = 0; i < SIZE - 1; i++) {
  11.         for (int j = 0; j < SIZE - 1; j++) {
  12.             tempArray[i][j] = decList[i][j];
  13.         }
  14.     }
  15.  
  16.     for (int i = 0; i < SIZE - 1; i++) {
  17.         for (int j = 0; j < SIZE - 1; j++) {
  18.             if (decList[j][i] > decList[j + 1][i]) {
  19.                 double temp = tempArray[j][i];
  20.                 tempArray[j][i] = tempArray[j + 1][i];
  21.                 tempArray[j + 1][i] = temp;
  22.             }
  23.         }
  24.     }
  25. }
  26.  
  27. int main() {
  28.     double list1[SIZE][SIZE], emptyList[SIZE][SIZE];
  29.     string input;
  30.    
  31.     cout << "Enter a 3 by 3 matrix row by row: " << endl;
  32.     for (int i = 0; i < SIZE; i++) {
  33.         getline(cin, input);
  34.         stringstream ss(input);
  35.         ss << input;
  36.         for (int j = 0; j < SIZE; j++) {
  37.             ss >> list1[i][j];
  38.         }
  39.     }
  40.  
  41.     cout << "The column sorted array is " << endl;
  42.    
  43.     sortColumns(list1, emptyList);
  44.    
  45.     for (int i = 0; i < SIZE; i++ ) {
  46.         for (int j = 0; j < SIZE; j++) {
  47.             cout << emptyList[i][j] << " ";
  48.         }
  49.         cout << endl;
  50.     }
  51.  
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement