C Programming

C Program – Reverse the Elements of an Array

Here we are going to reverse the elements of an array using C program.

Reverse the Elements of an Array :

ArrayRverse.c
#include<stdio.h>
int main(void)
{
    int i,j,temp;
    int arr[10] = {1,2,3,4,5,6,7,8,9,10};

    // Reversing the elements using temp variable.
    for(i=0,j=9; i<j; i++,j--){
        temp=arr[i];
        arr[i]=arr[j];
        arr[j]=temp;
    }

    printf("After reversing, the array is : ");
    for(i=0; i<10; i++){
        printf("%d  ",arr[i]);
    }

    printf("\n");
    return 0;
}

Output:

Terminal
After reversing, the array is: 10  9  8  7  6  5  4  3  2  1

Happy Learning :)

Found a mistake or something out of date? Tell us →

Written by

chandrashekhar

Founder of onlinetutorialspoint.com. Enterprise architect with 15+ years in healthcare technology, designing and running systems on AWS and Azure. Writes about building real things with AI, local AI hardware and cloud certifications.

Keep reading

Ask a question or leave a comment