Write a program for row wise sort for a square matrix?
Answers
Answered by
0
for(int i=0;i<arr.length;i++)
{
for(int j=0;j<arr.length;j++)
{
for(int k=j+1;k<arr.length;k++)
{
if(arr[i][j] > arr[i][k])
{
int temp = arr[i][j];
arr[i][j] = arr[i][k];
arr[i][k] = temp;
}
}
}
}
It will sort each row in ascending order. I wrote this program in comment section here. If there is any error let me know. I will help you to solve it.
{
for(int j=0;j<arr.length;j++)
{
for(int k=j+1;k<arr.length;k++)
{
if(arr[i][j] > arr[i][k])
{
int temp = arr[i][j];
arr[i][j] = arr[i][k];
arr[i][k] = temp;
}
}
}
}
It will sort each row in ascending order. I wrote this program in comment section here. If there is any error let me know. I will help you to solve it.
Similar questions
Economy,
7 months ago
Computer Science,
7 months ago
Math,
7 months ago
English,
1 year ago
Chemistry,
1 year ago