## Reverse array program in C

We can reverse array elements using different logic. After taking array element as input from user we will reverse the array.

For example, consider an array of 5 element.

int main_array[5] = {2, 4, 6, 8, 10};

Then we will reverse the array like this.

int rev_array[4] = {10, 8, 6, 4, 2};

However, in this C programming guide we will make some program to reverse an array. So, let’s go ahead.

## C program to reverse an array

``````// C program to reverse an array

#include <stdio.h>

int main(){
int j, k, num, main_array[50], rev_array[50];

printf("Enter how many integers you have as array element : ");
scanf("%d", &num);

printf("\nEnter all integers : \n");

for(j = 0; j < num ; j++){    // storing all element to main array
scanf("%d", &main_array[j]);
}

for (j = num - 1, k = 0; j >= 0; j--, k++){
rev_array[k] = main_array[j];
}

for (j = 0; j < num; j++){
main_array[j] = rev_array[j];
}

printf("\nThe reverse array is : \n");

for (j = 0; j < num; j++){
printf("%d ", main_array[j]);
}

return 0;
}``````

## Reverse array program using function

``````// reverse array program using function in c

#include <stdio.h>

void rev_function(int num, int arr[]){
int t, k;

for(k = 0; k < num / 2; k++){
t = arr[k];
arr[k] = arr[num - k - 1];
arr[num - k - 1] = t;
}
}

int main(){
int Num, i, main_arr[50];
printf("Enter the number of array element here : ");

scanf("%d", &Num);
printf("\nEnter all the array element : \n");

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

rev_function(Num, main_arr);

printf("\nThe reverse array is : \n");

for(i = 0 ;i < Num; i++){
printf("%d ", main_arr[i]);
}

return 0;
}``````

### Output of the reverse array program:

``````Enter the number of array element here : 5

Enter all the array element :
50 100 150 200 250

The reverse array is :
250 200 150 100 50``````

Previous page:Â  Smallest element in array

Next page:Â  Variable size and limit