0

How to find the largest number?

I want a program that finds where the largest digit in the number is located. Also, I want it to only accept input of 5-digit integer. That if, Input: 16549 Output: 9 = Right If, Input: 18237 Output: 8 = Unknown (The result is "unknown" because the digit is neither left/right or middle) The program should print whether "Left, Middle, Right, Unknown" Can you help me? This is what I did so far: https://code.sololearn.com/ca23A16A5A1a

16th Jun 2021, 5:42 PM
Eka
Eka - avatar
2 odpowiedzi
+ 2
Evan Fernandez If there is no restriction then you can convert your entered number to String then you can get largest value and also corresponding position of that value. Using that position you can print "Left, Right, Middle, Unknown" https://code.sololearn.com/cNxqYWAvCyKU/?ref=app I have a question if there is duplicate digit then what?
16th Jun 2021, 6:59 PM
A͢J
A͢J - avatar
+ 1
Evan Fernandez To accept only 5 digit number ,you can use condition (number>=10000 && number<=99999) While adding largest value ,take a counter and do count++ if count is 1 for right, 3 for middle, 5 for left. Else unknown May you can better it later I guess.. Hope it helps...
16th Jun 2021, 6:40 PM
Jayakrishna 🇮🇳