fork download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. int max_number(int value) {
  5. int max_number_value = 0;
  6. while (value) {
  7. max_number_value = std::max(max_number_value, value % 10);
  8. value /= 10;
  9. }
  10. return max_number_value;
  11. }
  12.  
  13. int main() {
  14. int value = 78421;
  15. std::cout << "max number is: " << max_number(value);
  16. }
  17.  
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
max number is: 8