Find maximum and minimum element in array

#include<stdio.h>
#include<conio.h>
int main()
{
int n,i,a[25],max,min;
clrscr();
printf("Enter number of elements");
scanf("%d",&n);
printf("Enter elements of array");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
max=min=a[0];
for(i=0;i<n;i++)
{
     if(a[i]>max)
    {
     max=a[i];
     }
     if(a[i]<min)
     {
      min=a[i];
     }
}#include<stdio.h>
#include<conio.h>
main()
{
int n,i,a[20],max,min;
clrscr();
printf("Enter number : ");
scanf("%d",&n);
printf("Enter array elements…\n");
for(i=0;i<n;i++)
{
printf("Enter element %d : ",i+1);
scanf("%d",&a[i]);
}
max=min=a[0];
for(i=0;i<n;i++)
{
if(a[i]>max)
max=a[i];
if(a[i]<min)
min=a[i];
}
printf("\nMin : %d",min);
printf("\nMax : %d",max);
getch();
}
printf("\n minimum element is %d",min);
printf("\n Maximum element is %d",max);
getch();
return 0;
}

0 comments:

Post a Comment