C program to read an array of integers and print its elements in reverse order using pointers.
/* C program using pointers to read an array of
integers and print its elements in reverse order.*/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void
main()
{
int
*iarr;
int
j,n;
printf("Enter
number of elements to be entered :");
scanf("%d",&n);
iarr=(int
*)malloc(n*sizeof(int));
printf("Enter
the elements : \n");
for(j=0;j<n;j++)
{
scanf("%d",&iarr[j]);
}
if(n==0)
{
exit(1);
}
printf("Elements
in reverse order are :\n");
for(j=n-1;
j>=0; j--)
{
printf("%d\n",iarr[j]);
}
}
Output:
Comments
Post a Comment