fork download
  1. //Xinnuo Wang CS1A chapter 5 , P.296, #13
  2. //
  3. /*******************************************************************************
  4. *
  5. * Display the Lagest and Smallest Number in Sentinel Program
  6. *-------------------------------------------------------------------------------
  7. * This program accepts a series of integers edded -99, and display the largest
  8. * and smallest numbers.
  9. *
  10. *-------------------------------------------------------------------------------
  11. * INPUT
  12. * numn : The accepted number.
  13. *
  14. * OUTPUT
  15. * max : The max number
  16. * min : The min number
  17. *
  18. *******************************************************************************/
  19. #include <iostream>
  20. using namespace std;
  21.  
  22. int main()
  23. {
  24. int num; //INPUT - The accepted number.
  25. int max, min;//OUTPUT
  26. //
  27. //Initialization
  28. cout<< "Enter a number" << endl;
  29. cin>> num;
  30. max = num;
  31. min = num;
  32. while(num!=-99)
  33. {
  34. if(num >max)
  35. max = num;
  36. if(num< min)
  37. min = num;
  38. cout<< "Enter a number" << endl;
  39. cin>> num;
  40. }
  41. //
  42. //Output Result
  43. cout <<"The max number is :"<<max<<endl;
  44. cout<< "The min number is :" << min<< endl;
  45. return 0;
  46. }
Success #stdin #stdout 0.01s 5284KB
stdin
12 23 66 99 0 22 -2 100 -99 77 1000000
stdout
Enter a number
Enter a number
Enter a number
Enter a number
Enter a number
Enter a number
Enter a number
Enter a number
Enter a number
The max number is :100
The min number is :-2