Advertisements
Advertisements
प्रश्न
If arrays Mand M + N are as shown below, write a program in Java to find the array N.
M =
संक्षेप में उत्तर
उत्तर
import java.util.*;
class AQ19{
public static void main(String args[]){
Scanner ob = new Scanner(System.in);
int M[][] = new int[3][3], N[][] = new int[3][3];
int MN[][] = new int[3][3);
int i, j;
// INPUT LOOP FOR MATRIX M
System.out.println("MATRIX M");
for (i = 0; i < 3; i++)
{System.out.println("Enter the elements in row " + i);
for (j = 0; j < 3; j++)
M[i][j] = ob.nextlnt();
}
// INPUT LOOP FOR MATRIX M+N
System.out.println("MATRIX M+N");
for (i = 0; i < 3; i++)
{System.out.printIn("Enter the elements in row " + i);
for (i = 0; j < 3; j++)
MN[i][j] = ob.nextInt();
}
// FINDING MATRIX N FROM MATRIX MN AND MATRIX M
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
N[i][j] = MN[i][j] - M[i][j];
}
// OUTPUT LOOP FOR MATRIX N
for (i = 0; i < 3; i++)
{System.out.println();
for (j = 0; j < 3; j++)
System.out.print(N[i][j] + "\t");
}
}}
shaalaa.com
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 3: Arrays (Single Dimensional and Double Dimensional) - EXERCISES [पृष्ठ २४३]