fork download
  1. //Amari Mosley CSC5 Chapter 4, P.220 #1
  2. //
  3. /**************************************************************
  4. *
  5. * Determine The Maximum and Minimum
  6. * ____________________________________________________________
  7. * This program will determine which of two numbers is smaller, and larger.
  8. *
  9. * Computation is based on the conditional operator:
  10. * (expression) ? value_if_true : value_if_false
  11. * ____________________________________________________________
  12. * INPUT
  13. * num1 : First number entered by user
  14. * num2 : Second number entered by user
  15. *
  16. * OUTPUT
  17. * max : Larger of the two numbers
  18. * min : Smaller of the two numbers
  19. *
  20. **************************************************************/
  21.  
  22. #include <iostream>
  23. #include <iomanip>
  24. using namespace std;
  25.  
  26. // Defining Main Function
  27. int main()
  28. {
  29. // Defining double Variables
  30. double num1, num2, max, min;
  31.  
  32. // Prompting user to enter two numbers
  33. cout << "Enter the first number: ";
  34. cin >> num1;
  35. cout << "Enter the second number: ";
  36. cin >> num2;
  37.  
  38. // Determining smaller and larger using the conditional operator
  39. max = (num1 > num2) ? num1 : num2;
  40. min = (num1 < num2) ? num1 : num2;
  41.  
  42. // Final Display
  43. cout << "The larger number is: " << max << endl;
  44. cout << "The smaller number is: " << min << endl;
  45.  
  46. return 0;
  47. }
Success #stdin #stdout 0.01s 5316KB
stdin
10
21
stdout
Enter the first number: Enter the second number: The larger number is: 21
The smaller number is: 10