C Program to find Largest and Smallest Number in an Array

/* C Program to find Largest and Smallest Number in an Array */
#include<stdio.h>
int main()
{
int a[10], Size, i, Minimum, Min_Position, Maximum, Max_Position;
printf(“\nEnter the size of an array  :  “);
scanf(“%d”,&Size);
printf(“\n Enter %d elements of an array: \n”, Size);
for(i=0; i<Size; i++)
{
scanf(“%d”,&a[i]);
}
  Minimum = a[0];
  Min_Position = 1;
  Maximum = a[0];
  Max_Position = 1;
for(i=1; i<Size; i++)
    {
    if(a[i]< Minimum)
      {
        Minimum = a[i];
        Min_Position = i+1;
}
   if(a[i]> Maximum)
      {
        Maximum=a[i];
        Max_Position = i+1;
      }
    }
  printf(“\n Smallest element = %d”, Minimum);
  printf(“\n Index position = %d”, Min_Position);
  printf(“\n Largest element = %d”, Maximum);
  printf(“\n Index position = %d”, Max_Position);
  return 0;
}

Leave a Reply

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

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>