Start New Discussion within our Software Development Community

My homework requires me to write a program for a matrix that bubble sorts in descending order, then multiply by two and output results Tried doing these in different ways, maybe, someone out there can help..

#include <iostream>
#include <iomanip>
#include < cmath>
using namespace std;

const int NO_OF_ROWS = 3;
const int NO_OF_COLUMNS =5;
void printmatrix(int matrix[NO_OF_ROWS][NO_OF_COLUMNS];
void bubble-sort (int matrix[NO_OF_ROWS][NO_OF_COLUMNS]
int main()
{
int matrix[NO_OF_ROWS][NO_OF_COLUMNS]
= { 80,95, 75, 65, 90, 95, 70, 85, 80, 55, 45, 75, 65, 100}
int row;
int col;
for (col = 0; col <NO_OF_COLUMNS; col++)
matrix[NO_OF_ROWS][NO_OF_COLUMNS] = 0;
for (row = 0; row < NO_OF_ROWS; row++)
matrix[NO_OF_ROWS][NO_OF_COLUMNS] = 0;
void printmatrix(int matrix[NO_OF_ROWS][NO_OF_COLUMNS];
for (row = 0; row < NO_OF_ROWS; row++)
{
for (col = 0; col <NO_OF_COLUMNS; col++)
cout << setw(5) << matrix[row][col] << " " ;
cout << "Original matrix " << endl;
}
void bubble-sort (int matrix[NO_OF_ROWS][NO_OF_COLUMNS]
{
int temp, i, j;
for (row = 0; row < NO_OF_ROWS; row++)
if (NO_OF_ROWS(i) > NO_OF_COL(j)
{
temp = NO_OF_ROWS(i);
NO_OF_ROWS = NO_OF_ROWS(j)
NO_OF_ROWS[j] = temp;
;
return 0;
}

The first part is ok but the bubble sort part is not right... Anyone? Its suppose to display the numbers in descending order as a matrix. (I got the ascending order earlier, but not able to print as a matrix) Inputs highly appreciated!

Well, if dealing with 2-d is your problem, try this. len n = r * c of the matrix.

use buble sorting, on matrix[0][0] to matrix[0][n-1]. It will sort, the matrix, left to right & top to bottom

And also, in the code, you use, NO_OF_ROWS as a matrix, as a function & as an integer. What is this?

This question has already been answered. Start a new discussion instead.