fork(1) download
  1. //Cameron Pham CS1A Chapter 7, p. 444, #2
  2. //
  3. /***************************************************************
  4. * DISPLAY MAXIMUM AND MINIMUM ARRAY VALUES
  5. ****************************************************************
  6. * This program accepts 10 float values from the user and stores
  7. * them in an array. It then determines and displays the maximum
  8. * and minimum values stored in the array.
  9. * ______________________________________________________________
  10. * INPUT:
  11. * Values // The 10 numbers entered by the user
  12. *
  13. * OUTPUT:
  14. * Maximum // The maximum value in the array
  15. * Minimum // The minimum value in the array
  16. ***************************************************************/
  17.  
  18. #include <iostream>
  19. using namespace std;
  20.  
  21. int main()
  22. {
  23. // Initialize variables
  24. const int SIZE = 10;
  25. float values[SIZE]; // Stores the 10 numbers
  26. float maximum; // Stores the maximum number
  27. float minimum; // Stores the minimum number
  28.  
  29. // Ask the user to enter 10 numbers
  30. for (int i = 0; i < SIZE; i++)
  31. {
  32. cout << "Enter value #" << (i + 1) << ": ";
  33. cin >> values[i];
  34. }
  35.  
  36. // Initialize the maximum and minimum values
  37. // using the first element in the array
  38. maximum = values[0];
  39. minimum = values[0];
  40.  
  41. // Search the array for the maximum and minimum values
  42. for (int i = 1; i < SIZE; i++)
  43. {
  44. if (values[i] > maximum)
  45. {
  46. maximum = values[i];
  47. }
  48.  
  49. if (values[i] < minimum)
  50. {
  51. minimum = values[i];
  52. }
  53. }
  54.  
  55. // Display the results
  56. cout << endl << "maximum value: " << maximum << endl;
  57. cout << "minimum value: " << minimum << endl;
  58.  
  59. return 0;
  60. }
Success #stdin #stdout 0.01s 5320KB
stdin
67.67 900 41 87 -5677886 0.11112 700.90867 4 1000000000.8 1
stdout
Enter value #1: Enter value #2: Enter value #3: Enter value #4: Enter value #5: Enter value #6: Enter value #7: Enter value #8: Enter value #9: Enter value #10: 
maximum value: 1e+09
minimum value: -5.67789e+06