Write a program using a pointer to read in an array of integers and print its elements in reverse order.
Code :
#include<stdio.h>
#include<conio.h>
void main()
{
int i, arr[30];
int *ptr;
ptr = &arr[0];
printf("\nEnter 5 integers into array: \n");
for (i = 0; i < 5; i++)
{
scanf("%d", ptr);
ptr++;
}
ptr = &arr[4];
printf("\nElements of array in reverse order are :\n");
for (i = 5; i >0; i--)
{
printf("\n %d ", i, *ptr);
ptr--;
}
getch();
}
Output:
No comments:
Post a Comment