C Program to Array Rotation - Source Code, Output & Execution Flow

C Program to Array Rotation

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

#include <stdio.h>
int main() {
    int a[] = {1, 2, 3, 4, 5};
    int n = 5, i, first = a[0];
    for (i = 0; i < n - 1; i++) a[i] = a[i + 1];
    a[n - 1] = first;
    for (i = 0; i < n; i++) printf("%d ", a[i]);
    return 0;
}
2 3 4 5 1

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.