Search This Blog

Friday, October 7, 2011

Write a program to find Max and Min number from a given set of numbers

   1:  #include<stdio.h>
   2:  #include<conio.h>
   3:  void main()
   4:  {
   5:  int n,i;
   6:  float x;
   7:  float min= 1.0E38, max=-1.0E38;
   8:  printf("How many num do you want to enter:  ");
   9:  scanf("%d",&n);
  10:  i=1;
  11:      while(i<=n)
  12:      {
  13:      printf("Enter the num %d:  ",i);
  14:      scanf("%f",&x);
  15:      if(x>max)
  16:      max=x;
  17:      if(x<min)
  18:      min=x;
  19:      i++;
  20:      }
  21:  printf("\nThe max num is %f\n",max);
  22:  printf("\nThe min num is %f\n",min);
  23:  getch();
  24:  }

No comments:

Post a Comment