Answer to Question #326244 in C for nile2020

Question #326244

5. 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:

  1. Input a 3-digit integer.
  2. Print the largest digit in the integer.
  3. 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.
  4. 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.
  5. 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.

Input


1. A three-digit integer

Output

The first line will contain a message prompt to input the 3-digit integer.

The last line contains the largest digit of the inputted integer.

Enter·a·3-digit·integer:·173
Largest·=·7
1
Expert's answer
2022-04-09T17:54:15-0400
#include <stdio.h>


int main() {
    int x;
    int d, m;


    printf("Enter a 3 digit integer: ");
    scanf("%d", &x);


    m = x%10;
    x /= 10;
    d = x%10;
    x /= 10;
    if (d > m)  m = d;
    if (x > m)  m = d;


    printf("Lagest = %d\n", m);


    return 0;
}

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