fork download
  1. // Saliha Babar CS1A Chapter 7, Page 444, #1
  2. //
  3. /*****************************************************************************
  4.  * DETERMINE LARGEST AND SMALLEST VALUES
  5.  * ___________________________________________________________________________
  6.  * This program accepts 10 integers and determines the largest and the smallest
  7.  * value in that list.
  8.  *
  9.  * There is no specific formula for this program
  10.  * ___________________________________________________________________________
  11.  * INPUT
  12.  * numbers : user input for each integers
  13.  *
  14.  * OUTPUT
  15.  * smallest : smallest integer in the list
  16.  * largest : largest integer in the list
  17.  ******************************************************************************/
  18. #include <iostream>
  19. using namespace std;
  20.  
  21. int main() {
  22. const int maxNumbers = 10;
  23. int numbers[maxNumbers];
  24. int largest;
  25. int smallest;
  26.  
  27. // Get the user Input
  28. for ( int count = 0; count < maxNumbers ; count ++)
  29. {
  30. cout << "Enter an integer #" << (count + 1 ) << " :" ;
  31. cin >> numbers[count];
  32. cout << endl;
  33. }
  34.  
  35. // Determine the largest and smallest value
  36. largest = numbers[0];
  37. smallest = numbers[0];
  38.  
  39. for ( int count = 1 ; count < maxNumbers ; count ++)
  40. {
  41. if (numbers[count] < smallest )
  42. smallest = numbers[count];
  43.  
  44. if ( numbers[count] > largest )
  45. largest = numbers[count];
  46. }
  47.  
  48. cout << "The smallest integer is " << smallest << endl;
  49. cout << "The largest integer is " << largest << endl;
  50.  
  51. return 0;
  52. }
Success #stdin #stdout 0s 5280KB
stdin
1
2
3
45
56
5
-3
9
3
1000
stdout
Enter an integer #1 :
Enter an integer #2 :
Enter an integer #3 :
Enter an integer #4 :
Enter an integer #5 :
Enter an integer #6 :
Enter an integer #7 :
Enter an integer #8 :
Enter an integer #9 :
Enter an integer #10 :
The smallest integer is -3
The largest integer is 1000