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

Also Prepare Below Important Question
- Hibernate Interview Questions for 2+ years of experience
- 68 Most Important Microservices Interview Questions
- 60 Most Important Git Interview Questions
- 50+ Mostly asked Java Interview Questions for 6 Years Exp.
- 60+ Mostly Asked Java Interview Questions for 4 Years Exp
- 60+ Mostly asked Java Interview Question for 3+ Years
- 60+ Spring Boot interview questions for 4+ years Exp.
- 60+ Mostly Asked Spring Boot Interview Questions for 3+ Yrs
- Scenario Based Java 8 Coding Interview Questions (For Experienced)
- Python Program to add two numbers without addition operator
- Mostly Asked Java Interview Questions For 2 Yrs Experience
- Find All Pairs in Array whose Sum is Equal to given number Using Java
- Java Program to find GCD of two Numbers using Recursion
- Python Program to Separate Characters in a Given String
- Python Program to add two number using Recursion
- Python Program to Find Highest Frequency Element in Array
- Python Program to Merge two Arrays
- Perform left rotation by two positions in Array Using Python
- Python Program to Delete Element at Given Index in Array
- Python Program to Delete element at End of Array
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