package Mobile.Arrays;
import java.util.Scanner;
public class Matrix_Sum_Of_Diagonal_Elements
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[10][10];
int sum=0;
System.out.println("Enter elements for Matrix");
for(int i=1;i<=3;i++)
{
for(int j=1;j<=3;j++)
{
a[i][j]=sc.nextInt();
}
}
System.out.println("Matrix is");
for(int i=1;i<=3;i++)
{
for(int j=1;j<=3;j++)
{
System.out.print("\t"+a[i][j]);
}
System.out.print("\n");
}
System.out.print("Sum of Diagonal elements of the matrix is =");
for(int i=1;i<=3;i++)
{
for(int j=1;j<=3;j++)
{
if(i==j)
sum=sum+a[i][j];
}
}
System.out.print(" "+sum);
}
}
import java.util.Scanner;
public class Matrix_Sum_Of_Diagonal_Elements
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[10][10];
int sum=0;
System.out.println("Enter elements for Matrix");
for(int i=1;i<=3;i++)
{
for(int j=1;j<=3;j++)
{
a[i][j]=sc.nextInt();
}
}
System.out.println("Matrix is");
for(int i=1;i<=3;i++)
{
for(int j=1;j<=3;j++)
{
System.out.print("\t"+a[i][j]);
}
System.out.print("\n");
}
System.out.print("Sum of Diagonal elements of the matrix is =");
for(int i=1;i<=3;i++)
{
for(int j=1;j<=3;j++)
{
if(i==j)
sum=sum+a[i][j];
}
}
System.out.print(" "+sum);
}
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.