Answer to Question #310567 in C++ for Secret Agent

Question #310567

We've already tried comparing 3 numbers to see the largest among all, so let's try a more complicated mission where we locate where among the 5-digit integer is the largest one. There are only 4 possible cases for this mission:

  • if the largest digit is the first digit, print "Leftmost"
  • if the largest digit is the third digit, print "Middle"
  • if the largest digit is the last digit, print "Rightmost"
  • if none of the above is correct, print "Unknown"

Now, show me how far you've understood your lessons!

Input

A line containing a five-digit integer.

14632

Output

A line containing a string.

Middle






1
Expert's answer
2022-03-12T18:04:59-0500
#include <iostream>


using namespace std;


int main()
{
    int a;
    cin>>a;
    int fd=a/10000; // first digit
    int md=(a/100)%10; // middle digit
    int ld=a%10; // last digit
    if ((fd>md)&&(fd>ld))
    {
        cout<<"Leftmost";
    }
    else if ((md>fd)&&(md>ld))
    {
        cout<<"Middle";
    }
    else if ((ld>fd)&&(ld>md))
    {
        cout<<"Rightmost";
    }
    else cout<<"Unknown";
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment