C++: Trying to output the max and min: #include <iostream> using namespace std;
ID: 3784955 • Letter: C
Question
C++: Trying to output the max and min:
#include <iostream>
using namespace std;
int main(int argc, char**argv) {
int A, B, C;
//promote values for each input then read the data
cout << "Please Enter the Value of A : ";
cin >> A;
cout << "Please Enter the Value of B : ";
cin >> B;
cout << "Please Enter the Value of C : ";
cin >> C;
if (A > B & A > C)
{
cout << "Max number: " << A;
if (B < C)
cout << "Min number: " << C;
else
cout << "Min number: " << B;
}
else if (B > A & B > C)
cout << "Max number: " << B;
{
if (A < C)
cout << "Min number: " << A;
else
cout << "Min number: " << C;
}
else
cout << "Max number: " << C;
{
if (B < A)
cout << "Min number: " << B;
else
cout << "Min number: " << A;
}
return 0;
}
Explanation / Answer
In the above code snippest ;
You have to enter 3 values namely A,B,C.
In the given algorithm there are 2 cases:
1) if (A > B & A > C)
In short, A is max number, and if B<C then B is min number otherwise C is min number.
2) if (B > A & B > C)
Here, max number is B. Also if (A < C) then min number is A otherwise it will be C.Otherwise for whole condition max number is C.
If (B < A), then we have min number is B, else min number s A.
Thank you.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.