Advertisements
Advertisements
प्रश्न
Define a class to accept values into a 4 x 4 integer array. Calculate and print the NORM of the array.
NORM is the square root of sum of squares of all elements.
| 1 | 2 | 1 | 3 |
| 5 | 2 | 1 | 6 |
| 3 | 6 | 1 | 2 |
| 3 | 4 | 6 | 3 |
Sum of squares of elements = 1+4+1+9+25+4+1+36+9+36+1+4+9+16+36+9 = 201
NORM = Squareroot of 201 = 14.177446878757825
कोड लेखन
Advertisements
उत्तर
import java.util.*;
public class NormClass {
public static void main(String[] args) {
int sum=0;
double norm=0.0;
Scanner sc = new Scanner(System.in);
double[][] mat = new double[4][4];
System.out.println("Enter values for 4×4 matrix: ");
for (int i = 0; i <4; i++) {
for (int j= 0; j < 4; j++) {
mat[i][j] = scanner.nextDouble();
}
for (int i = 0; i < 4; i++) {
for (int j =0; j< 4; j++) {
sum+=mat[i][j];
norm=Math.sqrt(sum);
System.out.println("Norm of the matrix is :"+
norm);
}
}shaalaa.com
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
