Maximum and Minimum in Array Code

// Max and Min in Array.

#include<stdio.h>
main()
{
 int a[100],size,max,min,i;
 printf("Enter size Of Array\n");
 scanf("%d",&size);
 
 printf("Enter  Values\n");
 for(i=0;i<size;i++)
  scanf("%d",&a[i]);
 //Now consider first value maximum and minimum//
 max=a[0];min=a[0];
 
 for(i=0;i<size;i++)
 {
  if(a[i]>max)
  max=a[i];
     if(min>a[i])
     min=a[i];
 }
 printf("Maximum=%d\nMinimum=%d",max,min);
}

No comments:

Post a Comment