Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Written by Oles Bober
- #include <iostream>
- #include <sstream>
- using namespace std;
- const int SIZE = 3;
- void sortColumns (const double decList[][SIZE], double tempArray[][SIZE];) {
- for (int i = 0; i < SIZE - 1; i++) {
- for (int j = 0; j < SIZE - 1; j++) {
- tempArray[i][j] = decList[i][j];
- }
- }
- for (int i = 0; i < SIZE - 1; i++) {
- for (int j = 0; j < SIZE - 1; j++) {
- if (decList[j][i] > decList[j + 1][i]) {
- double temp = tempArray[j][i];
- tempArray[j][i] = tempArray[j + 1][i];
- tempArray[j + 1][i] = temp;
- }
- }
- }
- }
- int main() {
- double list1[SIZE][SIZE], emptyList[SIZE][SIZE];
- string input;
- cout << "Enter a 3 by 3 matrix row by row: " << endl;
- for (int i = 0; i < SIZE; i++) {
- getline(cin, input);
- stringstream ss(input);
- ss << input;
- for (int j = 0; j < SIZE; j++) {
- ss >> list1[i][j];
- }
- }
- cout << "The column sorted array is " << endl;
- sortColumns(list1, emptyList);
- for (int i = 0; i < SIZE; i++ ) {
- for (int j = 0; j < SIZE; j++) {
- cout << emptyList[i][j] << " ";
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement