Friday, 14 October 2016

Write a program to find smallest and highest number from an array?

Q1. : Write a program to find smallest and highest number from an array?

/*    ##################################
            Girfa : Student Help
            Program : Count Highest/smallest
            For more program visit : http://girfahelp.blogspot.in/2012/09/some-program-of-c-language.html
      ###################################
      */
#include<stdio.h>
#include<conio.h>
void main()
{
      int ar[5],i,small=0,big=0;
      clrscr();
      for(i=0;i<5;i++)

      {
            printf("Enter %d position number>> ",i+1);
            scanf("%d",&ar[i]);
      }
      small=big=ar[0];
      for(i=0;i<5;i++)
      {
            if(ar[i]<small)
                  small=ar[i];
            else if(ar[i]>big)
                  big=ar[i];

                                                                        
      }
      printf("\n\tInput Data\n\n");
      for(i=0;i<5;i++)
            printf("\t%d",ar[i]);
      printf("\n\n\tSmallest No. is %d\n\tBiggest No. is %d",small,big);
      getch();
}

Download C Source Code

No comments:

Post a Comment