MATLAB Develop and program a method for reordering the colum

MATLAB: Develop and program a method for reordering the columns of a (m x n) array based on placing the first row of the array in ascending order. Cannot use sort function.

Solution

void main()
{
static int array1[8][8], array2[8][8];
int i, j, k, a, m, n;

printf(\"Enter the order of the matrix \ \");
scanf(\"%d %d\", &m, &n);
printf(\"Enter co-efficients of the matrix \ \");
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
scanf(\"%d\", &array1[i][j]);
array2[i][j] = array1[i][j];
}
}
printf(\"The given matrix is \ \");
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
printf(\" %d\", array1[i][j]);
}
printf(\"\ \");
}
printf(\"After arranging rows in ascending order\ \");
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
for (k =(j + 1); k < n; ++k)
{
if (array1[i][j] > array1[i][k])
{
a = array1[i][j];
array1[i][j] = array1[i][k];
array1[i][k] = a;
}
}
}
}
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
printf(\" %d\", array1[i][j]);
}
printf(\"\ \");
}
printf(\"After arranging the columns in descending order \ \");
for (j = 0; j < n; ++j)
{
for (i = 0; i < m; ++i)
{
for (k = i + 1; k < m; ++k)
{
if (array2[i][j] < array2[k][j])
{
a = array2[i][j];
array2[i][j] = array2[k][j];
array2[k][j] = a;
}
}
}
}
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
printf(\" %d\", array2[i][j]);
}
printf(\"\ \");
}
}

MATLAB: Develop and program a method for reordering the columns of a (m x n) array based on placing the first row of the array in ascending order. Cannot use so
MATLAB: Develop and program a method for reordering the columns of a (m x n) array based on placing the first row of the array in ascending order. Cannot use so

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site