Sunday 25 September 2011

Program to find max and min no from given numbers


#include <iostream.h>
#include <conio.h>


main()
{
int n, min, max;
cout << "Enter positive integers. Terminate input with 0.\n";
cin >> n;
for (min = max = n; n > 0; )
{
if (n < min) min = n;                   //min and max are the smallest
      else if (n > max) max = n;              //and largest of the n that
cin >> n;                               //have been read so far
}
cout << "min = " << min << " and max = " << max << endl;
getch();
}                  

No comments:

Post a Comment