Share this:
ISC 2021 Computer Practical Question 3 – Matrix Program
-WRITTEN BY CODERGURUJI
Solution :
import java.util.*;
class Q3
{
public static void main(String args[])
{ int p=0,s=0,s1=0;
Scanner sc=new Scanner(System.in);
System.out.println(“enter m*n”);
int m=sc.nextInt();
int n=sc.nextInt();
int a[][]=new int[m][n];
int b[]=new int[1000];
int c[][]=new int[m][n];
for(int i=0;i
{
for(int j=0;j
{
a[i][j]=sc.nextInt();
}
}
System.out.println(“ORIGINAL MATRIX”);
for(int i=0;i
{
for(int j=0;j
{
if((i==0)||(i==m-1)||(j==0)||(j==n-1))
{
s=s+a[i][j];
}
System.out.print(a[i][j]+” “);
}
System.out.println();
}
System.out.println(“SUM OF THE BOUNDARY ELEMENTS(UNSORTED)= “+s);
for(int i=0;i
{
for(int j=0;j
{
b[p]=a[i][j];
p++;
}
}
for(int i=0;i
{
for(int j=0;j
{
if(b[j]
{
int temp=b[j];
b[j]=b[j+1];
b[j+1]=temp;
}
}
}
p=0;
System.out.println(“SORTED MATRIX”);
for(int i=0;i
{
for(int j=0;j
{
c[i][j]=b[p];
System.out.print(b[p]+” “);
p++;
if((i==0)||(i==m-1)||(j==0)||(j==n-1))
{
s1=s1+c[i][j];
}
}
System.out.println();
}
System.out.println(“SUM OF THE BOUNDARY ELEMENTS(SORTED)= “+s1);
}
}
—————————————-end—————————————