Write a program to find the largest and the smallest element in an array using pointer to 1D-array.

Leave a Comment
#include<stdio.h>
#include<conio.h>


int main()
{
int i,h,l,n,a[100];
int *ptr;
printf("\nEnter the max limit:");
scanf("%d",&n);
ptr=a;
for(i=0;i {
printf("\nEnter the element:");
scanf("%d",(ptr+i));
}
ptr=a;
for(i=0;i<n;i++)

{
if(h<*(ptr+i))
h=*(ptr+i);
if(l>*(ptr+i))
l=*(ptr+i);
}
printf("\nThe lowest number in the list is %d", l);
printf("\nThe highest number in the list is %d", h);
getche();
return 0;
}

0 comments: