fork download
  1. //Xinnuo Wang CS1A chapter7 #1
  2. /*******************************************************************************
  3.  * Display Largest and Smallest Array Value
  4.  * _____________________________________________________________________________
  5.  * The program accepts 10 values into an array and displays the largest and
  6.  * smallest values stored in the array
  7.  *
  8.  * _____________________________________________________________________________
  9.  * Input:
  10.  * num : The accepted numbers in the array.
  11.  * Output:
  12.  * Largest : The largest value in the array.
  13.  * Smallest : The smallest value in the array.
  14.  *
  15.  * ****************************************************************************/
  16. #include <iostream>
  17. using namespace std;
  18.  
  19. int main()
  20. {
  21. double num[10];
  22. double Largest;
  23. double Smallest;
  24. Largest = num[0];
  25. Smallest = num[0];
  26. for (int i = 0; i < 10; i++)
  27. {
  28. cout << "Enter the value: " << (i + 1) ;
  29. cin >> num[i];
  30. cout << num[i]<< endl;
  31. if (Largest < num[i])
  32. {
  33. Largest = num[i];
  34.  
  35. }
  36. if (Smallest > num[i])
  37. {
  38. Smallest = num[i];
  39.  
  40. }
  41. }
  42. cout << "The largest number is: "<< Largest << endl;
  43. cout << "The smallest number is: "<< Smallest << endl;
  44.  
  45.  
  46. return 0;
  47. }
Success #stdin #stdout 0s 5300KB
stdin
-99.99 2711 33.3 99.9 88 66 11 12 13 14.9
stdout
Enter the value: 1-99.99
Enter the value: 22711
Enter the value: 333.3
Enter the value: 499.9
Enter the value: 588
Enter the value: 666
Enter the value: 711
Enter the value: 812
Enter the value: 913
Enter the value: 1014.9
The largest number is: 2711
The smallest number is: -99.99