#include<stdio.h>
main()
{
int a[100],max,min,pos1,pos2,n,i;
clrscr();
printf("\nEnter the total number of elements\n");
scanf("%d",&n);
printf("\nEnter the elements one by one: \n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
max=a[0];
min=a[0];
pos1=pos2=0;
for(i=1;i<n;i++)
{
if(a[i]>max)
{
max=a[i];
pos1=i;
}
if(a[i]<min)
{
min=a[i];
pos2=i;
}
}
printf("\nLargest value is %d and found at %d Position\n",max,pos1+1);
printf("\nSmallest Value is %d and found at %d Position\n",min,pos2+1);
getch();
}
Comments
Post a Comment