Answer to Question #281143 in C for Secret

Question #281143

6. Largest Digit


by CodeChum Admin



This one is a bit tricky. You're going to have to isolate each digit of the integer to determine which one is the largest, so good luck!





Instructions:



Input a 3-digit integer.


Print the largest digit in the integer.


Tip #1: Use % 10 to get the rightmost digit. For example, if you do 412 % 10, then the result would be the rightmost digit, which is 2.


Tip #2: On the other hand, use / 10 to remove the rightmost digit. For example, if you do 412 / 10, then the result would be 41.


Tip #3: You'd have to repeat Tip #1 and Tip #2 three times for this problem because the input is a 3-digit integer.


Instructions



Input one 3-digit integer.


Print the largest digit in the integer. (Hint: use % 10 to get the rightmost digit and / 10 to remove it)


Input



A line containing a three-digit integer.





173


Output



A line containing a single-digit integer





7

1
Expert's answer
2021-12-20T10:00:00-0500
#include<bits/stdc++.h>
using namespace std;


int main()
{
    int n,a,b,c;
    
    cout<<"Enter a Number: ";
    cin>>n;
    
    a = n % 10;
    n = n / 10;
    
    b = n % 10;
    n = n / 10;
    
    c = n % 10;
    n = n / 10;
    
    if (a > b and a > c)
    {
        cout<<"Largest among three numbers: "<<a;
    }
    
    if (b > a and b > c)
    {
        cout<<"Largest among three numbers: "<<b;
    }
    
    if (c > b and c > a)
    {
        cout<<"Largest among three numbers: "<<c;
    }
   
    
    
}

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