fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int number;
  5. printf("请输入一个不多于五位数的整数:");
  6. scanf("%d", &number);
  7.  
  8. // 提取各个位上的数字
  9. int number_wan = number / 10000; // 提取万位
  10. int number_qian = (number % 10000) / 1000; // 提取千位
  11. int number_bai = (number % 10000 % 1000) / 100; // 提取百位
  12. int number_shi = (number % 10000 % 1000 % 100) / 10; // 提取十位
  13. int number_ge = number % 10000 % 1000 % 100 % 10; // 提取个位
  14.  
  15. // 根据不同的位数情况逆序输出
  16. if (number_wan == 0) {
  17. printf("%d %d %d %d %d\n", number_ge, number_shi, number_bai, number_qian, number_wan);
  18. } else if (number_wan != 0 && number_qian == 0) {
  19. printf("%d %d %d %d\n", number_ge, number_shi, number_bai, number_wan);
  20. } else if (number_wan != 0 && number_qian != 0 && number_bai == 0) {
  21. printf("%d %d %d\n", number_ge, number_shi, number_wan);
  22. } else if (number_wan != 0 && number_qian != 0 && number_bai != 0 && number_shi == 0) {
  23. printf("%d %d\n", number_ge, number_wan);
  24. } else if (number_wan != 0 && number_qian != 0 && number_bai != 0 && number_shi != 0 && number_ge == 0) {
  25. printf("%d\n", number_wan);
  26. } else {
  27. printf("%d %d %d %d %d\n", number_ge, number_shi, number_bai, number_qian, number_wan);
  28. }
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0s 5284KB
stdin
45
stdout
请输入一个不多于五位数的整数:5 4 0 0 0