SEARCH MAXIMUM AND MINIMUM ELEMENT IN AN INTEGER ARRAY

/*PROGRAM TO SEARCH MAXIMUM AND MINIMUM ELEMENT IN AN INTEGER ARRAY*/
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,s,l,a[10],loc=0;
clrscr();
printf(“Enter any ten elements in the array:\n”);
for(i=0;i<10;i++)
scanf(“%d”,&a[i]);
printf(“Elements in the array are:\n”);
for(i=0;i<10;i++)
printf(“%4d”,a[i]);
printf(“\n”);
//SEARCHING LARGEST ELEMENT IN THE ARRAY
l=a[0];
for(i=0;i<10;i++)
{
if(l<=a[i])
{
l=a[i];
loc=i+1;
}
}
printf(“Largest element in the array: %d\nLocation of largest element: %d\n”,l,loc);
//SEARCHING SMALLEST ELEMENT IN THE ARRAY
s=a[0];
loc=0;
for(i=0;i<10;i++)
{
if(s>=a[i])
{
s=a[i];
loc=i+1;
}
}
printf(“Smallest element in the array: %d\nLocation of smallest element: %d”,s,loc);
getch();
}

Leave a Reply

Your email address will not be published. Required fields are marked *