Program in C to display the contents of an array in the reverse order using pointer.


C File =>


/* Write a program to display the elements of an array containing n integers in the reverse order using a pointer to the array.*/


#include<stdio.h>
#include<stdlib.h>
int main()
{
     int *ptr,arr[30],n,i;
     printf("\n Enter value of n : ");
     scanf("%d",&n);
     for(i=0;i<n;i++)
    {
       printf("\n Enter array element%d ",i+1);
       scanf("%d",&arr[i]);
    }
   //moving pointer at last element
        ptr=&arr[n-1];
      printf("\n Array elements in reverse :\n");
      for(i=0;i<n;i++)
     {
           printf("%d\t",*ptr);
           ptr=ptr-1;
      }
   return 0;
 }

Comments

Popular posts from this blog

Write a program to allocate memory dynamically for n integers. Accept the elements and calculate their sum and average

C program to accept names of n cities and search for city named “Pune”.