Saturday, 15 July 2017

Greatest Number from array using Pointer

Q : Write a program using pointer to find greatest number in an array.

Solution : 

#include<stdio.h>
#define MAX 5
void main()
{
     int ar[MAX],*pt,h,i;
     for(i=0;i<MAX;i++)
     {
          printf("Enter Number>> ");
          scanf("%d",&ar[i]);
     }

     h=ar[0];
     for(pt=ar,i=0;i<MAX;pt++,i++)
     {
          if(*pt>h)
              h=*pt;
     }
     printf("Highest Value is %d",h);
    
}