-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrace.java
More file actions
30 lines (30 loc) · 743 Bytes
/
trace.java
File metadata and controls
30 lines (30 loc) · 743 Bytes
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
import java.util.*;
class test
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("enter the order");
int r=sc.nextInt();
int c=sc.nextInt();
System.out.println("enter the elements");
int a[][]=new int[r][c];
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
a[i][j]=sc.nextInt();
}
}
int sum=0;
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
sum=sum+a[i][i];
}
}
System.out.println("trace of the matrix is:");
System.out.println(sum);
}
}