fork download
  1. //Xinnuo Wang CS1A chapter 5 , P.296, #13
  2. //
  3. /*******************************************************************************
  4. *
  5. * Display the Lagest and Smallest Number
  6. *-------------------------------------------------------------------------------
  7. * This program accepts a series of integers, and displays the largest and
  8. * smallest numbers. The value -99 ends the series.
  9. *
  10. *-------------------------------------------------------------------------------
  11. * INPUT
  12. * num : The accepted series 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: ";
  29. cin >> num;
  30. cout<< num << endl;
  31. max = num;
  32. min = num;
  33. while(num!=-99)
  34. {
  35. if(num >max)
  36. max = num;
  37. if(num< min)
  38. min = num;
  39. cout<< "Enter a number: ";
  40. cin>> num;
  41. cout << num << endl;
  42. }
  43. //
  44. //Output Result
  45. cout <<"The max number is :"<<max<<endl;
  46. cout<< "The min number is :" << min<< endl;
  47. return 0;
  48. }
Success #stdin #stdout 0.01s 5320KB
stdin
12 23 66 99 0 22 -2 100 -99 77 1000000
stdout
Enter a number: 12
Enter a number: 23
Enter a number: 66
Enter a number: 99
Enter a number: 0
Enter a number: 22
Enter a number: -2
Enter a number: 100
Enter a number: -99
The max number is :100
The min number is :-2