Answer to Question #258893 in C++ for yan

Question #258893

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!

1
Expert's answer
2021-10-30T13:32:14-0400
#include<iostream>
using namespace std;
int main()
{
	int n;
	cout<<"Enter a number: ";
	cin>>n;
	if((n%10)>(n%1000) && (n%10)>(n%1000)){
		cout<<"leftmost";
	}
	else if((n%100)>(n%10) && (n%100)>(n%1000)){
		cout<<"Middle";
	}
	else if((n%1000)>(n%10) && (n%1000)>(n%100)){
		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

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS