C Program – Reverse the Elements of an Array

By | 2017-09-20T03:33:40+00:00 September 20th, 2017|c-program|1 Comment

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

[box type=”success” align=”alignleft” class=”” width=”100%”]

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

[/box]

Happy Learning 🙂

About the Author:

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+ ,

One Comment

  1. Milana Travis October 25, 2017 at 2:19 pm - Reply

    Thank you very much for your blog.

    I enjoyed reading this article.

Leave A Comment