在线编译器 C

#include <stdio.h> int main() { int a, min, max; scanf("%d", &a); min = a%10; max = a%10; while (a>0) { if(a%10 > max) { max = a%10; } if(a%10 < min) { min = a%10; } a = a / 10; } printf("%d", max*min); return 0; }
1) This code reads an integer, then finds its smallest and largest digits. Finally, it prints the product of these two digits.

2) Hint: Trace through the loop with a sample number like 482 to see how `a%10` extracts digits and `a/10` removes them.
Hint: Notice that the initial values of `min` and `max` are set to the last digit of the input number before the loop begins.