Sunday , 20 August 2017
Latest Posts
Home » Class 12 » ISC 2013 [Question 2] Practical Paper Solved (Mirror Image Matrix)

# ISC 2013 [Question 2] Practical Paper Solved (Mirror Image Matrix)

#### Question:

Write a program to declare a square matrix A[ ] [ ] of order (M x 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 matrix.
(c) Display the mirror image matrix.

Test your program with the sample data and some random data:

Example 1

INPUT : M = 3
4       16      12
8        2       14
4        1        3

OUTPUT :

ORIGINAL MATRIX

4       16       12
8         2       14
4         1        3

MIRROR IMAGE MATRIX

12      16      4
14       2      8
3         1      6

Example 2

INPUT : M = 22

OUTPUT : SIZE OUT OF RANGE

#### Programming Code:

```/**
* The class ImageMatrix_ISC2013 inputs a square matrix and finds its image matrix
* and finally prints both of them
* @author : www.javaforschool.com
* @Program Type : BlueJ Program - Java
* @Question Year : ISC Practical 2013 Question 2
*/

import java.io.*;
class ImageMatrix_ISC2013
{
public static void main(String args[])throws IOException
{
System.out.print("Enter the size of the square matrix : ");

if(m>2 && m<20) //checking given condition
{
int A[][]=new int[m][m];
System.out.println("Enter the elements of the Matrix : ");
for(int i=0;i<m;i++)
{
for(int j=0;j<m;j++)
{
}
}
System.out.println("*********************");
System.out.println("The original matrix:");
System.out.println("*********************");
for(int i=0;i<m;i++)
{
for(int j=0;j<m;j++)
{
System.out.print(A[i][j]+"t");
}
System.out.println();
}

// creating the Image Matrix
int B[][]=new int[m][m];
for(int i=0;i<m;i++)
{
int k=0;
for(int j=m-1;j>=0;j--)
{
B[i][k]=A[i][j];
k++;
}
}

//Printing both the Matrix
System.out.println("*********************");
System.out.println("The Mirror Image:");
System.out.println("*********************");
for(int i=0;i<m;i++)
{
for(int j=0;j<m;j++)
{
System.out.print(B[i][j]+"t");
}
System.out.println();
}
}
else
System.out.println("Output : Size Out Of Range");
}
}```

#### Output:

Enter the size of the square matrix : 4
Enter the elements of the Matrix:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
*********************
The original matrix:
*********************
1        2      3      4
5        6      7      8
9     10     11     12
13   14     15     16
*********************
The Mirror Image:
*********************
4       3       2      1
8       7       6      5
12   11      10     9
16   15      14    13

## [Question 2] ISC 2017 Computer Practical Paper Solved – Quiz Result

Solution of Program 2 of ISC 2017 Computer Science Paper 2 (Practical) Exam. Java program to input the answers of each participant row-wise and calculate their marks

1. sir can u please explain why are we using variable k while generating mirror image of matrix?

• variable ‘k’ is being used to refer to the column part of the new mirror image matrix ‘B’ which should start from 0.
We have to store the last element of the first row of original matrix into as the first element in the new mirror image matrix.
So, variable ‘j’ is referring to the column part of original matrix going in reverse order from ‘m-1’ to 0. And hence, to refer to the column part of the new mirror image matrix we are using variable ‘k’ going from 0 to ‘m-1’

2. Biprodeep@gmail.com

Sir, the code you supplied here in the solution of program 2 of ISC 2013(practical) doesn’t tallies with the output you created down….look carefully the case when the user inputs an even order for the mirror matrix ………….you have not handled the different inputs i.e. for odd and for even ……………………likewise I did it accurate……………just glance over the following code…….any try to find the error in your code……..this will benefit many students who learn programming from here…
Yours Sincerely,
Biprodeep Roy.
CORRECTED CODE : –

/**
* ISC 2013:Program 2
*
* @author (Biprodeep Roy)
* @version (1.0)
*/
import java.util.*;
class MirrorMatrix
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print(“INPUT:-nEnter the size of the square matrix : “);
int m=sc.nextInt();
if(m>2 && m<20) //checking given condition
{
System.out.println("Input Validated:-");
}
else
System.out.println("OUTPUT:-nSize Out Of Range");
int A[][]=new int[m][m];
System.out.println("Enter the elements of the Matrix : ");
for(int i=0;i<m;i++)
{
for(int j=0;j<m;j++)
{
A[i][j]=sc.nextInt();
}
}
System.out.println("OUTPUT:-n*********************");
System.out.println("The original matrix:");
System.out.println("*********************");
for(int i=0;i<m;i++)
{

for(int j=0;j<m;j++)
{

System.out.print(A[i][j]+"t");

}
System.out.println();
}
// creating the Image Matrix
int B[][]=new int[m][m];
if(m%2!=0)
{
for(int i=0;i=0;j–)
{

B[i][k]=A[i][j];

k++;

}

}
}
else
{
for(int i=0;i=0;j–)
{
if(j==((m-2)/2)||j==(m/2))
B[i][k]=A[i][k];
else
B[i][k]=A[i][j];
k++;
}
}
}
//Printing both the Matrix.
System.out.println(“*********************”);

System.out.println(“The Mirror Image:”);

System.out.println(“*********************”);
for(int i=0;i<m;i++)
{

for(int j=0;j<m;j++)

{

System.out.print(B[i][j]+"t");

}

System.out.println();

}
}
}

• Hello Biprodeep,
The code given by us is absolutely fine. There was a typing error in the output generated. You don’t need to handle even and odd condition in this program. Thank you for your concern.
Have a nice day. 🙂

• No disrespect , but you could’ve just swapped and done the program without wasting space for extra DD array. Here’s the integral part:
for(int i=0;i<m;i++)
{
for(int j=0;j<(m/2);j++)
{
Temp=a[i][j];
a[i][j]=a[i][m-1-j];
a[i][m-1-j]=temp;
}
}