Knowee
Questions
Features
Study Tools

A mirror image of a 2D array of m*n, elements of the first and the last columns are interchanged.Second and one before the last interchanged and so on. The middle column remains fixed. Onlythe columns of a mirror image are interchanged row remains unaffected.Write a C program to do the following.a) Declare a 2D integer array called matrix of size 5 by 5.b) Input set of positive numbers and store in the array.Enter 1,1 :………….Enter 1,2 :………….Enter 1,3 :………….c) Display the array in the tabular format.5 4 3 7 68 1 2 9 27 3 4 1 03 6 9 2 31 4 9 3 0d) Find the mirror image of the matrix without using an additional array.e) Display the new array in the tabular format.6 7 3 4 52 9 2 1 80 1 4 3 73 2 9 6 30 3 9 4 1Save your program as 2AQ2b.c

Question

A mirror image of a 2D array of m*n, elements of the first and the last columns are interchanged.Second and one before the last interchanged and so on. The middle column remains fixed. Onlythe columns of a mirror image are interchanged row remains unaffected.Write a C program to do the following.a) Declare a 2D integer array called matrix of size 5 by 5.b) Input set of positive numbers and store in the array.Enter 1,1 :………….Enter 1,2 :………….Enter 1,3 :………….c) Display the array in the tabular format.5 4 3 7 68 1 2 9 27 3 4 1 03 6 9 2 31 4 9 3 0d) Find the mirror image of the matrix without using an additional array.e) Display the new array in the tabular format.6 7 3 4 52 9 2 1 80 1 4 3 73 2 9 6 30 3 9 4 1Save your program as 2AQ2b.c

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a simple C program that accomplishes the task:

#include <stdio.h>

int main() {
    int matrix[5][5];
    int i, j, temp;

    // Input numbers into the array
    for(i = 0; i < 5; i++) {
        for(j = 0; j < 5; j++) {
            printf("Enter %d,%d :", i+1, j+1);
            scanf("%d", &matrix[i][j]);
        }
    }

    // Display the array in tabular format
    printf("\nOriginal Matrix:\n");
    for(i = 0; i < 5; i++) {
        for(j = 0; j < 5; j++) {
            printf("%d ", matrix[i][j]);
        }
        printf("\n");
    }

    // Find the mirror image of the matrix without using an additional array
    for(i = 0; i < 5; i++) {
        for(j = 0; j < 5/2; j++) {
            temp = matrix[i][j];
            matrix[i][j] = matrix[i][5-j-1];
            matrix[i][5-j-1] = temp;
        }
    }

    // Display the new array in tabular format
    printf("\nMirror Image Matrix:\n");
    for(i = 0; i < 5; i++) {
        for(j = 0; j < 5; j++) {
            printf("%d ", matrix[i][j]);
        }
        printf("\n");
    }

    return 0;
}

This program first takes input from the user and stores it in a 2D array. It then prints the original matrix. After that, it finds the mirror image of the matrix by swapping the elements of the first and last columns, second and second last columns, and so on. The middle column remains unchanged. Finally, it prints the mirror image matrix.

This problem has been solved

Similar Questions

5 4 3 7 68 1 2 9 27 3 4 1 03 6 9 2 31 4 9 3 0d) Find the mirror image of the matrix without using an additional array.e) Display the new array in the tabular format.6 7 3 4 52 9 2 1 80 1 4 3 73 2 9 6 30 3 9 4 1Save your program as 2AQ2b.c

Ben is studying matrices and wants to write a program that swaps two rows of a matrix (N, M), the program takes an input matrix, swaps the specified rows, and then displays the modified matrix.Assist him with the program.Input format :The first line consists of two space-separated integers N and M, representing the number of rows and columns in the matrix.The next N lines contain M space-separated integers each, representing the elements of the matrix.The last line consists of two space-separated integers r1 and r2, representing the row numbers to be interchanged.Output format :If the input row numbers r1 or r2 are invalid (less than 1 or greater than the number of rows), the output prints "Invalid row numbers".Otherwise, the modified matrix is printed after swapping the specified rows.

Problem StatementRaj, a coding hobbyist, is working on a binary matrix manipulation program. He wants to create a simple tool to input binary values in the form of a matrix and display the entered binary pattern. Write a program that takes the dimensions (rows and columns) of a binary matrix as input, reads the binary values, and then displays the entered binary pattern grid.Input format :The first line of input consists of two space-separated integers r, and c, representing the number of rows and columns of the binary matrix.The next r lines consist of c space-separated binary values (0 or 1) representing the elements of the array.Output format :The output displays the entered binary pattern grid.Refer to the sample output for the formatting specifications.Code constraints :In the given scenario, the test cases fall under the following constraints:1 ≤ rows, cols ≤ 5Each cell of the matrix contains either 0 or 1.Sample test cases :Input 1 :4 31 0 11 1 01 1 10 0 0Output 1 :1 0 1 1 1 0 1 1 1 0 0 0 Input 2 :5 51 0 1 0 10 1 0 1 01 0 1 0 10 1 0 1 01 0 1 0 1Output 2 :1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 Input 3 :1 10Output 3 :0

If A is an m x n matrix then AT (Transpose of A) is an n x m matrix, such that rows of A become columns of AT and columns of A become rows of AT.Given a 2D array, you have to implement the given function,int** Transpose(int** matrix, int rowCount, int columnCount);Implement the function to find the transpose of the matrix and return the new matrix as output.Input:matrix:2 46 8Output:2 64 8Explanation: Values 2 and 4 in the first row become the first column in the returned matrix.Similarly, values 6 and 8 in the second row become the second column in the returned matrix.Sample inputmatrix:1 2 3 4 5 6Sample Output1 4 2 5 3 6

Write a C program to read a 2D array of N*M class numbers and print square elements of 2D array  using pointers and functions.Sample Input2 3(Read row and column size)1 2 32 1 2Sample Output1 4 94 1 4

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.