Answer to Question #145478 in C for aaryan

Question #145478

Write a program to 4 X 4 matrix. Input the elements in the matrix and rotate the elements by one position of each row.


1
Expert's answer
2020-11-19T16:48:52-0500
#include <stdio.h>

int main() {
    int arr[4][4];
    int i, j, a, b, f;
    printf("\nInput numbers to 4*4 matrix");

    for (i = 0; i < 4; i++) {
        for (j = 0; j < 4; j++) {
            printf("\nKey in the [%d][%d]) value", i + 1, j + 1);
            scanf("%d", &arr[i][j]);
        }
    }

    for (i = 0; i < 4; i++) {
        for (j = 0, f = 0; j < 4; j++) {
            if (i != j && f == 0)
                continue;

            a = arr[i][j];
            b = arr[j][i];
            arr[i][j] = b;
            arr[j][i] = a;
            f = 1;
        }
    }

    for (i = 0; i < 4; i++) {
        for (j = 0; j < 4; j++)
            printf("%d ", arr[i][j]);

        printf("\n");
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS