-
Notifications
You must be signed in to change notification settings - Fork 0
/
traceofmat.java
32 lines (30 loc) · 798 Bytes
/
traceofmat.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.util.*;
class traceofmat
{
public static void main(String args[])
{
int sum=0;
Scanner obj = new Scanner(System.in);
System.out.println("how many row");
int r = obj.nextInt();
System.out.println("how many coln");
int c = obj.nextInt();
int a[][] = new int[10][10];
System.out.println("enter the elements into the array");
for(int i=0;i<r;i++)
for(int j=0;j<c;j++)
a[i][j] = obj.nextInt();
System.out.println("matrix a");
for(int i=0;i<r;i++)
{
System.out.println();
for(int j=0;j<c;j++)
System.out.print(a[i][j]+" ");
}
for(int i=0;i<r;i++)
for(int j=0;j<c;j++)
if(i==j)
sum = sum +a[i][j];
System.out.println("the trace of the matrix is "+sum);
}
}