How to find greatest element in array using pointer?
CODE
How to find greatest
element in array using pointer?
//Write a program to
find greatest element in an array using pointer…
int main()
{
int *p,a[10],n,max,i;
printf("\n enter N:");
scanf("%d",&n);
p=a;
for(i=0;i<n;i++)
{
printf("\n value at
a[%d]:",i);
scanf("%d",(p+i));
}
max=*p;
for(i=1;i<n;i++)
{
if(*(p+i)>max)
max=*(p+i);
}
printf("\n greatest=%d",max);
}
Output:
enter N:5
value at a[0]:4
value at a[1]:8
value at a[2]:6
value at a[3]:2
value at a[4]:5
greatest=8
How to find greatest element in array using pointer?
Reviewed by Unknown
on
December 31, 2018
Rating:
No comments:
If you have any doubt or query ,comment below: