Basic

Switch Case

Goto

Operators

if Statement

Nested if

While Loop

For Loop

Array

2D Array

Patterns

Excersises


C Program to Reverse an Array Elements


Write a C program to reverse the element of an array.

  • Takes input for the number of elements and stores them in an array.
  • Reads and stores n integers into the array using a loop.
  • Uses a reverse loop to access elements from the end of the array.
  • Prints the array elements in reverse order.
Example : pgm.c
#include <stdio.h>

int main() {
    int n, arr[100];

    printf("Enter the number of elements: ");
    scanf("%d", &n);

    printf("Enter %d elements:\n", n);
    for(int i = 0; i < n; i++) {
        scanf("%d", &arr[i]);
    }

    // Reverse the array
    printf("Reversed array:\n");
    for(int i = n - 1; i >= 0; i--) {
        printf("%d ", arr[i]);
    }

    return 0;
}

Output:

Enter number of elements: 4
Enter 4 elements:
5
8
12
22
Reversed array:
22 12 8 5