Looping a number and taking away each digit of it is so much fun, but I wanted to try out a much more complex task: getting the largest digit among them all.
Think you can handle the job?
Instructions:
Input
A line containing an integer.
214
Output
A line containing an integer.
4
#include <stdio.h>
int main() {
int x, d, max_d;
scanf("%d", &x);
max_d = x%10;
x = x / 10;
while (x > 0) {
d = x%10;
if (d > max_d) {
max_d = d;
}
x = x / 10;
}
printf("%d\n", max_d);
return 0;
}
Comments
Leave a comment