C Program to Rotate Matrix Elements - Source Code, Output & Execution Flow

C Program to Rotate Matrix Elements

This tutorial explains c program to rotate matrix elements with C source code, sample output, and step-by-step execution flow.

#include <stdio.h>
int main() {
    int a[3][3] = {{1,2,3},{4,5,6},{7,8,9}};
    int i, j;
    printf("90 degree rotation:
");
    for (i = 0; i < 3; i++) {
        for (j = 2; j >= 0; j--) printf("%d ", a[j][i]);
        printf("
");
    }
    return 0;
}
90 degree rotation:
7 4 1 
8 5 2 
9 6 3

In this program, the input is read first when required, the core logic is applied step by step, and the final result is displayed using printf(). Follow the execution flow beside the code to understand how each statement contributes to the output.

Sai Kishore Randhi, author
About the author

Sai Kishore Randhi

Embedded systems, VLSI, and chip design

Sai Kishore writes about embedded systems, VLSI, chip design, and the programming concepts behind modern hardware.

View LinkedIn profile ↗