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[30], i, j, num, temp; //asking user to enter size of an array elements printf("\nEnter no of elements : "); scanf("%d", &num); //Reading elements in an array 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
C PROGRAMMING TUTORIALS
- C Program For Pascal Triangle
- C Program to Print Prime Numbers from 1 to 100
- C Program to Find LCM and GCD of Two Numbers
- C Program to Add Spaces in a String
- C Program To Add Digits Of A Number
- C Program To Find Leap Year
- C Program To Append Data Into A File
- C Program to Accept Only Integer Values
- C Program To Arrange Numbers In Descending Order
- C Program to Add Days to Date
- C Program to Add Two Fractions
- C Program To Reverse A Number
- C Program to Find Maximum and Minimum Numbers
- C Program to Read a Text File
- C Program to Convert Decimal to Hexadecimal
- C Program to Convert Decimal to Binary
- C Program to Convert Celsius to Fahrenheit
- C Program To Find Absolute Value
- Ternary Operator Program in C
- C Program For Addition Table Using For Loop