fork download
  1. //Amari Mosley CSC5 Chapter 7, P. 444, #1
  2. /***************************************************************
  3.  *
  4.  * COMPUTE LARGEST AND SMALLEST
  5.  * ____________________________________________________________
  6.  * This program lets the user enter 10 values into an array and
  7.  * displays the largest and smallest values stored in it.
  8.  *
  9.  * Computation is based on comparing array elements:
  10.  * if (values[count] > values[HighIndex])
  11.  * ___________________________________________________________
  12.  * INPUT*
  13.  * values: 10 integer values inputted by user through a loop
  14.  *
  15.  * OUTPUT*
  16.  * HighestValue: The largest value entered into the array
  17.  * LowestValue: The smallest value entered into the array
  18.  *
  19.  **************************************************************/
  20. #include <iostream>
  21. using namespace std;
  22.  
  23. int main() {
  24. const int SIZE = 10;
  25. int values[SIZE];
  26. int HighIndex = 0;
  27. int LowIndex = 0;
  28.  
  29. cout << "Enter 10 integer values:\n";
  30.  
  31. // Prompts user to enter values into the array
  32. for (int count = 0; count < SIZE; count++) {
  33. cout << "Value " << (count + 1) << ": ";
  34. cin >> values[count];
  35. }
  36.  
  37. // Calculates Highest and Lowest Values
  38. for (int count = 1; count < SIZE; count++) {
  39. if (values[count] > values[HighIndex]) {
  40. HighIndex = count;
  41. }
  42. if (values[count] < values[LowIndex]) {
  43. LowIndex = count;
  44. }
  45. }
  46.  
  47. // Output Complete Report
  48. cout << endl;
  49. cout << " \n LARGEST AND SMALLEST VALUES REPORT \n ";
  50. cout << "Largest Value: " << values[HighIndex] << " \n ";
  51. cout << "Smallest Value: " << values[LowIndex] << " \n ";
  52.  
  53. return 0;
  54. }
Success #stdin #stdout 0.01s 5316KB
stdin
1
2
3
4
5
6
7
8
9
10
stdout
Enter 10 integer values:
Value 1: Value 2: Value 3: Value 4: Value 5: Value 6: Value 7: Value 8: Value 9: Value 10: 
 
 LARGEST AND SMALLEST VALUES REPORT 
 Largest Value: 10 
 Smallest Value: 1