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