C Program To Read integers into an array and Reversing them using Pointers

C Program To Read integers into an array and Reversing them using Pointers

#include<stdio.h>
#include<conio.h>
#define MAX 50

void main()
{

   int size, i, arr[MAX];
   int *ptr;

   ptr = &arr[0];

   printf("Enter the size of array : \n");
   scanf("%d", &size);   //input from user

   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");    //Print Output On screen

   for (i = size - 1; i >= 0; i--)
   {
      printf("\nElement%d is %d : ", i, *ptr);   //Print Output On screen
      ptr--;
   }

}

Related Posts