fork download
  1. //Ryan Robateau CSC5 Chapter 7, P. 444, #1
  2. //
  3. /*******************************************************************************
  4.  * Compute Min and Max
  5.  * _____________________________________________________________________________
  6.  * This program allows the user to input values into an
  7.  * array and computes the largest and smallest values stored in
  8.  * the array.
  9.  * _____________________________________________________________________________
  10.  ******************************************************************************/
  11. #include <iostream>
  12. using namespace std;
  13.  
  14. int main()
  15. {
  16.  
  17. const int ARRAY_SIZE = 10;
  18. int storage[ARRAY_SIZE];
  19. int max; // INPUT - hold the highest number
  20. int min; // INPUT - hold the lowest number
  21. int count;
  22.  
  23.  
  24. for (count = 0; count < ARRAY_SIZE; count++)
  25. {
  26. cout << "Please enter a value for index " << count + 1 << ":" << endl;
  27. cin >> storage[count];
  28. }
  29.  
  30.  
  31. max = storage[0];
  32. for (count = 0; count < ARRAY_SIZE; count++)
  33. {
  34. if (storage[count] > max)
  35. max = storage[count];
  36. }
  37.  
  38.  
  39. min = storage[0];
  40. for (count = 0; count < ARRAY_SIZE; count++)
  41. {
  42. if (storage[count] < min)
  43. min = storage[count];
  44. }
  45.  
  46. // OUTPUT RESULTS
  47. cout << "\nThe largest number is: " << max;
  48. cout << "\nThe smallest number is: " << min;
  49.  
  50. return 0;
  51. }
Success #stdin #stdout 0.01s 5304KB
stdin
1
2
3
4
5
6
7
8
9
10
stdout
Please enter a value for index 1:
Please enter a value for index 2:
Please enter a value for index 3:
Please enter a value for index 4:
Please enter a value for index 5:
Please enter a value for index 6:
Please enter a value for index 7:
Please enter a value for index 8:
Please enter a value for index 9:
Please enter a value for index 10:

The largest number is: 10
The smallest number is: 1