Let's do this in easiest way.....
ISC Practical 2020
****************************HERE IS THE CODE:
****************************
import java.util.*;
public class Bubble_Sort_In_Matrix_Descending_Order
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int n=0,temp,i,j;
System.out.println("Enter the number of Rows");
int r=sc.nextInt();
System.out.println("Enter the number of Columns");
int c=sc.nextInt();
int arr[][]=new int[r][c];
int brr[]=new int[r*c];
System.out.println("Enter the elements of Matrix");
for( i=0;i<r;i++)
{
for( j=0;j<c;j++)
{
arr[i][j]=sc.nextInt();
}
}
System.out.println("INPUT MATRIX IS:-");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
brr[n++]=arr[i][j];
System.out.print(arr[i][j]+" ");
}
System.out.println("");
}
for(int l=0;l<n-1;l++)
{
for(int k=0;k<n-1;k++)
{
if(brr[k]<brr[k+1])
{
temp=brr[k];
brr[k]=brr[k+1];
brr[k+1]=temp;
}
}
}
n=0;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
arr[i][j]=brr[n++];
}
}
System.out.println("REARRANGED MATRIX IS:-");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
System.out.print(arr[i][j]+" ");
}
System.out.println("");
}
}
}
****************************************************************************
Comments
Post a Comment