Monday , October 23 2017
Home / c-program / C Program – Reverse the Elements of an Array

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 :


#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;
}

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

Happy Learning 🙂

About chandrashekhar

Hi Folks, you have reach this so far, that shows you like what you are learning. Then why don't you support us to improve for bettor tutorials by leaving your valuable comments and why not you keep in touch with us for latest updates on your favorite blog @ facebook , twitter , Or Google+ ,

Recommended

C Program – Find Largest and Smallest number in an Array

C Program to find the largest and smallest number in an array. Largest and Smallest …

Leave a Reply

Your email address will not be published. Required fields are marked *