C Program to Print Array Elements in Reverse Order

Ex: Write a C program to print given array elements in reverse order. How to write a C program to print array elements in reverse order. C program to print array elements in reverse order.

Input from user:

Enter the limit: 5

Enter the elements:
10
20
30
40
50

Expected output:

Given elements in reverse order:
50 40 30 20 10




  Step by step logic of the given program:


1. Accept input (limit) from user declare variables say no and arr.

2. Run a loop from no-1 to 0 in decremented  style. The loop structure look like: for(i=no-1;i>=0;i--)

3. Inside the body of loop print current array elements using arr[i].






  Program to Print Array Elements in Reverse Order :

#include<stdio.h>
#define max 100
void main()
{
int arr[max],i,no;

printf("Enter how many elements you are going to enter\n");
scanf("%d",&no);

printf("Enter elements:\n");
for(i=0;i<no;i++)
{
scanf("%d",&arr[i]);
}

printf("Elements in Reverse order:\n");
for(i=no-1;i>=0;i--)
{
printf("%d ",arr[i]);
}
}


Above program shows the following output:

C Program to Print Array Elements in Reverse Order, C program to reverse array elements

No comments:

Post a Comment

If you have any doubts, please discuss here...👇