# C Program To Reverse An Array

C Program To Reverse An Array. If you are looking for C Program for Reverse Array, here in this tutorial we will help you to learn how to write a C program to reverse an array elements.

## C Program To Reverse An Array

Learn how to write a C program to reverse an array. Writing a C reverse array program can be done using various techniques but here in this program, we show how to write a program to reverse an array logic in a proper way.

### Reversing An Array Elements Example

These are some examples of reversing array elements.

Input : arr[] = {11, 12, 13}
Output : arr[] = {13, 12, 11}

Input : arr[] = {41, 51, 11, 21}
Output : arr[] = {21, 11, 51, 41}

### C Program To Reverse An Array Source Code

Find the below source code to reverse an array and how to write c program to reverse an array using while loop.

```/* C Proram to reverse an array using while loop - ReverseArray.C */

#include<stdio.h>

int main() {
//variable declaration
int arr, i, j, num, temp;
//asking user to enter size of an array elements
printf("\nEnter no of elements : ");
scanf("%d", &num);

for (i = 0; i < num; i++) {
scanf("%d", &arr[i]);
}

j = i - 1; // j will Point to last element of an array
i = 0; // i will be pointing to first element of ann array

while (i < j) {
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
i++; // increment i
j--; // decrement j
}

//Printing output of an array elements in a reverse order
printf("\nThe result after reversing of an array : ");
for (i = 0; i < num; i++) {
printf("%d \t", arr[i]);
}

return (0);
}```

### C Program To Reverse An Array Output

Enter no of elements : 3

41     51     11     21

The result after reversing of an array

21     11     51     41