fork download
  1. //Nathan Dominguez CSC5 Chapter 7, P. 444, #1
  2. //
  3. /*******************************************************************************
  4.  *
  5.  * Display the Largest and Smallest Values
  6.  * _____________________________________________________________________________
  7.  * This program will allow the user to enter 10 values into an
  8.  * array. The program should then display the largest and smallest
  9.  * values stored into the array.
  10.  * _____________________________________________________________________________
  11.  * INPUT
  12.  * value :The values entered in the array
  13.  *
  14.  * OUTPUT
  15.  * large :The largest value in the array
  16.  * small :The smallest value in the array
  17.  *
  18.  ******************************************************************************/
  19. #include <iostream>
  20. using namespace std;
  21.  
  22. int main()
  23. {
  24. const int aSize = 10; // The size of the array
  25. int value[aSize]; // INPUT - The values entered in the array
  26. int large; // OUTPUT - The largest value in the array
  27. int small; // OUTPUT - The smallest value in the array
  28. int count; // LOOP - counter
  29.  
  30. //
  31. // Input the 10 values
  32. for(count = 0; count < aSize; count++)
  33. {
  34. cout << "Enter the a value for value "<< (count + 1);
  35. cout << ": " << endl;
  36. cin >> value[count];
  37. }
  38. //
  39. // Aquires Largest Value of Array
  40. large = value[0];
  41. for(count = 0; count < aSize; count++)
  42. {
  43. if (value[count] > large)
  44. large = value[count];
  45. }
  46. //
  47. // Aquires Smallest Value of Array
  48. small = value[0];
  49. for(count = 0; count < aSize; count++)
  50. {
  51. if (value[count] < small)
  52. small = value[count];
  53. }
  54. //
  55. // Display Output largest and smallest value
  56. cout << "The largest value in the array is " << large << endl;
  57. cout << "The smallest value in the array is " << small;
  58. return 0;
  59. }
Success #stdin #stdout 0.01s 5304KB
stdin
2
3
4
5
6
7
8
9
0
1
stdout
Enter the a value for value 1: 
Enter the a value for value 2: 
Enter the a value for value 3: 
Enter the a value for value 4: 
Enter the a value for value 5: 
Enter the a value for value 6: 
Enter the a value for value 7: 
Enter the a value for value 8: 
Enter the a value for value 9: 
Enter the a value for value 10: 
The largest value in the array is 9
The smallest value in the array is 0