Answer to Question #326245 in C for nile2020

Question #326245

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-10T05:24:11-0400
#include <stdio.h>


int main() {
    int n;
    int largest=-1;


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


    for (int i=0; i<3; i++) {
        if (largest < n%10)
            largest = n%10;
        n = n / 10;
    }
    printf("Largest = %d", largest);


    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