Fundamentals of Computer Programming - Old Questions

7. Write a program using pointers to read in an array of integers and print its elements in reverse order.

6 marks | Asked in 2073

#include<stdio.h>

#include<conio.h>

#define MAX 30

void main()

{

  int size, i, arr[MAX];

  int *ptr;

  clrscr();

  ptr=&arr[0];

  printf("Enter the size of array : ");

  scanf("%d",&size);

  printf("Enter %d integers into array:n",size);

   for(i=0;i<size;i++)

   {

   scanf("%d",ptr);

   ptr++;

   }

  ptr=&arr[size-1];

  printf("Elements of array in reverse order are:n");

  for(i=size-1;i>=0;i--)

   {

   printf("nElement%d is %d :",i,*ptr);

   ptr--;

   }

  getch();

}