- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to print the elements in a reverse order from an array in C?
Try to print the elements in reverse order by following an algorithm given below −
Step1 − Declare an array of size 5
Step 2 − Enter the 5 elements in memory using for loop
Step 3 − Display elements in reverse order
By decrementing for loop
The only logic is to reverse the elements is For loop −
for(i=4;i>=0;i--){ //Displaying O/p// printf("array[%d] :",i); printf("%d
",array[i]); }
Example
Following is the C program to reverse the elements −
#include<stdio.h> void main(){ //Declaring the array - run time// int array[5],i; //Reading elements into the array// printf("Enter elements into the array:
"); //For loop// for(i=0;i<5;i++){ //Reading User I/p// printf("array[%d] :",i); scanf("%d",&array[i]); } //Displaying reverse order of elements in the array// printf("The elements from the array displayed in the reverse order are :
"); for(i=4;i>=0;i--){ //Displaying O/p// printf("array[%d] :",i); printf("%d
",array[i]); } }
Output
When the above program is executed, it produces the following result −
Enter elements into the array: array[0] :23 array[1] :13 array[2] :56 array[3] :78 array[4] :34 The elements from the array displayed in the reverse order are: array[4] :34 array[3] :78 array[2] :56 array[1] :13 array[0] :23
- Related Articles
- Python program to print the elements of an array in reverse order
- How to print one dimensional array in reverse order?
- C# Program to display the last three elements from a list in reverse order
- C++ program to reverse an array elements (in place)
- C program to reverse an array elements
- Print prime numbers from 1 to N in reverse order
- Print n smallest elements from given array in their original order
- Print array elements in alternatively increasing and decreasing order in C++
- How to reverse the order of a JavaScript array?
- Print Even Positions Elements from an Array in Java
- How to reverse the elements of an array using stack in java?
- Print the last occurrence of elements in array in relative order in C Program.
- How to access elements from an array in C#?
- Write a C program to print the message in reverse order using for loop in strings
- How to print list values in reverse order using Collections.reverse() in Android?

Advertisements