Instructions:
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
#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;
}
Comments
Leave a comment