Answer to Question #269298 in C for Neil

Question #269298

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


Enter a 3-digit integer: 109
Largest = 9


Enter a 3-digit integer: 666
Largest = 6
1
Expert's answer
2021-11-21T17:34:19-0500
#include <stdio.h>

int main()
{
    int x, lagest;
    printf("Enter a 3-digit integer: ");
    scanf("%d", &x);

    lagest = 0;
    if (x%10 > lagest) {
        lagest = x%10;
    }
    x = x / 10;
    if (x%10 > lagest) {
        lagest = x%10;
    }
    x = x / 10;
    if (x%10 > lagest) {
        lagest = x%10;
    }
    
    printf("Lagest = %d\n", lagest);

    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