Write a program to declare a square matrix a[][] of order (m × m) where ‘m’ is the number of rows and the number of columns such that ‘m’ must be greater than 2 and less than 20. Allow the user to input integers into this matrix. Display appropriate error message for an invalid input. Perform the following tasks:
(a) Display the input matrix.
(b) Create a mirror image of the inputted matrix.
(c) Display the mirror image matrix.
Test your program for the following data and some random data:
Example 1:
INPUT: M = 3
4 16 12
8 2 14
6 1 3
OUTPUT:
ORIGINAL MATRIX
4 16 12
8 2 14
6 1 3
MIRROR IMAGE MATRIX
12 16 4
14 2 8
3 1 6
Example 2:
INPUT: M = 22
OUTPUT: SIZE OUT OF RANGE
import java.io.*;
class Mirror{
public static void main(String args[])throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("m = ");
int m = Integer.parseInt(br.readLine());
if(m < 3 || m > 19){
System.out.println("SIZE OUT OF RANGE");
return;
}
int a[][] = new int[m][m];
int b[][] = new int[m][m];
int p = 0;
int q = m - 1;
System.out.println("Enter matrix elements:");
for(int i = 0; i < m; i++){
q = m - 1;
for(int j = 0; j < m; j++){
a[i][j] = Integer.parseInt(br.readLine());
b[p][q] = a[i][j];
q--;
}
p++;
}
System.out.println("ORIGINAL MATRIX");
for(int i = 0; i < m; i++){
for(int j = 0; j < m; j++){
System.out.print(a[i][j] + "\t");
}
System.out.println();
}
System.out.println("MIRROR IMAGE MATRIX");
for(int i = 0; i < m; i++){
for(int j = 0; j < m; j++){
System.out.print(b[i][j] + "\t");
}
System.out.println();
}
}
}
4 replies on “Mirror Image of Matrix ISC 2013 Practical”
Sir,how to find LCM of 2 numbers by recursive function in JAVA?Can you please show me the code?
https://www.happycompiler.com/hcf-lcm-recursive-java/
Sir,a program is given which states that:
WAP in Java to accept 2 numbers. Then find the HCF as well as the LCM of the 2 nos using recursive function.
Follow https://www.happycompiler.com/recursion-examples/ to access recursive function to find the GCD and then calculate LCM as product of the two numbers divided by GCD.