Slip 26 - B) Write a program to display the elements of an array containing n integers in the Reverse order using a pointer to the array.

Solution:


#include<stdio.h>
void main()
{   int size, i, arr[30];
   int *ptr;
    ptr = &arr[0];
   printf("\nEnter the size of array : ");
   scanf("%d", &size);
   printf("\nEnter %d integers into array: ", size);
   for (i = 0; i < size; i++) {
      scanf("%d", ptr);
      ptr++;
   }
   ptr = &arr[size - 1];
   printf("\nElements of array in reverse order are :");
    for (i = size - 1; i >= 0; i--) {
      printf("\nElement%d is %d : ", i, *ptr);
      ptr--;
   }
    getch();
}

Post a Comment

0 Comments