Get minimum and maximum number

Take n elements into an integer array and fimd the minimum and maximum value . Also find the possition .
‪#‎include<stdio.h>
#include<conio.h>
void main()
{
int i , a[100] , max , maxp , min , min p, n ;
printf("\n enter how many numbers you want = ");
scanf("%d",&n);
printf("\nenter numbers = ");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
i=0;
max=a[i];
min=a[i];
maxp=i+1;
minp=i+1;
for(i=1;i<n;i++ )
{
if(max<a[i])
{max=a[i];
maxp=i+1;
}
}
for(i=1;i<n;i++ )
{
if(min>a[i])
{min=a[i];
minp=i+1;
}
}
printf("\n\nmaximum = %d , possition = %d , \n minimum = %d , possition = %d ",max,maxp,min,minp);
getch();
return;
}

Post a Comment

0 Comments