In this tutorial, we are going to learn to write a C program to reverse the Array. Here we are not just going to print the array in reverse order, but we will reverse the original array.
You can check our program in C to print the array in reverse order.
There are multiple ways to write the reverse array program like using the secondary array or without using any secondary array. We will see both ways.
C program to reverse an Array with the help of a second array
#include <stdio.h> int main() { int size, i, startIndex,lastIndex; printf("Enter size of the array: "); scanf("%d", &size); //taking size of the elements int arr[size], reverse[size]; //Taking the input in array for(i = 0; i < size; i++) { printf("Please give value for index %d : ",i); scanf("%d",&arr[i]); } startIndex = 0; lastIndex = size - 1; while(lastIndex >= 0) { //Copying value from the original array to //new reverse array staring from last index reverse[startIndex] = arr[lastIndex]; startIndex++; lastIndex--; } printf("Array After Reversing : \n"); for(i=0; i<size; i++) { printf("%d\t", reverse[i]); } return 0; }
Output

Reverse an Array without using second array and temp variable in C
#include<stdio.h> int main() { int size, i, startIndex,lastIndex; printf("C Program to reverse an Array \n"); printf("enter the size of an array : "); scanf("%d",&size); //Taking size of array array int arr[size]; //Taking the input in array for(i = 0; i < size; i++) { printf("Please give value for index %d : ",i); scanf("%d",&arr[i]); } startIndex = 0; lastIndex = size - 1; //Here is the logic to reverse an array //Logic we are following swapping two variable //without using 3rd variable while (startIndex < lastIndex) { arr[startIndex] = arr[startIndex] + arr[lastIndex]; arr[lastIndex] = arr[startIndex]- arr[lastIndex]; arr[startIndex] = arr[startIndex]- arr[lastIndex]; startIndex++; lastIndex--; } printf("Reversed array is \n"); for (i=0; i < size; i++) printf("%d \t", arr[i]); return 0; }
Output

Share on
Also Prepare Below Important Question
- Java Program to Perform Left Rotation on Array Elements by Two
- Java Program to Perform Right Rotation on Array Elements by Two
- Java Program to Print Odd Numbers from Array
- Java Program to Print All Even Numbers in Array
- Java Program to Find the Sum of Array Elements
- Java Program to Delete Element of Array At Given Location
- Java Program to Delete a given Element of Array
- Java Program to Delete Element at End of Array
- Java Program to Insert Element in Array at given Location
- Java Program to Insert Element At the End of Array
- Java Program to Print Length of an Array
- Reverse Array without using Second Array or inplace Reversal Java Program
- Java Program to Print Array in Reverse Order
- Java Program to Sort String Character in Descending order
- Java Program to Sort String in Ascending Order
- Java Program to Print non Repeating Characters in String
- Java Program to Find Sum of Integers in the String
- Java Program to Remove Duplicates From String
- Java Program to Concatenate two Strings
- Java Program to Check if two Strings are Same
Interview Questions Categories
C Programming Interview Preparation
Core Java Programming Interview Preparation
- Core Java Programming Coding Questions
- Core Java Pattern Programming Questions
- Core Java Programming Interview Questions