Programming Challenge Chapter 4 – Q #1 Minimum/Maximum – Tony Gaddis – Starting Out With C++

Programming Challenge Chapter 4 – Q #1  Minimum/Maximum – Tony Gaddis – Starting Out With C++


Minimum/Maximum

Problem: -

Write a program that asks the user to enter two numbers. The program should use the conditional operator to determine which number is the smaller and which is the larger.

Solution: -

#include<iostream>

using namespace std;

int main()

{

      //Declare Variables

      int num1, num2;

      int min, max;


      //Take Input From The User

      cout << "Enter 1st Number: ";

      cin >> num1;

      cout << "Enter 2nd Number: ";

      cin >> num2;


      //Use Conditional Operator For Minimum & Maximum

      min = num1 < num2 ? num1 : num2;

      max = num1 > num2 ? num1 : num2;

 

 

      //Output On The Scree

      cout << "Smaller Number is " << min << endl;

      cout << "Larger Number is " << max << endl;

 

      //Return Value To The Main Function

      return 0;

}

This is the solution of this question




OUTPUT OF THIS QUESTION


Explanation of this Solution

Solution Explain With Comments in Solution.


Also, I attach CPP file of this problem. You can download this file

Click Here to Download This File


Post a Comment

0 Comments