Monday 8 April 2019

CP : Reverse Order using Pointer


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

Code :

#include<stdio.h>
#include<conio.h>


void main() 
{
   int  i, arr[30];
   int *ptr;

   ptr = &arr[0];

   printf("\nEnter 5 integers into array: \n");
   for (i = 0; i < 5; i++)
        {
      scanf("%d", ptr);
      ptr++;
        }

   ptr = &arr[4];

   printf("\nElements of array in reverse order are :\n");
   for (i = 5; i >0; i--)
    {
      printf("\n %d  ", i, *ptr);
      ptr--;
    }

   getch();
}

Output:





No comments:

Post a Comment

LAB 7 Arduino with Seven Segment Display || Arduino Tutorial || Code and Circuit Diagram || Project

  LAB 7 Arduino with Seven Segment Display || Arduino Tutorial || Code and Circuit Diagram || Project Dear All We will learn how to Connec...