-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNormal_and_trace.java
More file actions
33 lines (32 loc) · 1.15 KB
/
Normal_and_trace.java
File metadata and controls
33 lines (32 loc) · 1.15 KB
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
33
import java.util.Scanner;
public class Normal_and_trace {
public static void main(String[] args) {
// Program to Find the Normal and Trace of a Matrix
Scanner sc = new Scanner(System.in);
System.out.print("Enter row and column length = ");
int rc = sc.nextInt();
int [][] Nor_tra = new int[rc][rc];
System.out.println("Enter the data");
for(int i = 0; i < rc; i++){
for(int j = 0; j < rc; j++){
Nor_tra[i][j] = sc.nextInt();
}
}
System.out.println("Normal Of Matrix = " +findNormalOfMatrix(Nor_tra, rc));
System.out.println("Trace Of Matrix = " +findTraceOfMatrix(Nor_tra, rc));
}
public static int findNormalOfMatrix (int Nor_tra[][], int rc){
int s = 0;
for(int i = 0; i < rc; i++){
for(int j = 0; j < rc; j++){
s += (Nor_tra[i][j]) * (Nor_tra[i][j]);
}
} return (int)Math.sqrt(s);
}
public static int findTraceOfMatrix (int Nor_tra[][], int rc){
int s = 0;
for(int i = 0; i < rc; i++){
s += Nor_tra[i][i];
} return s;
}
}