fork(3) download
  1. #include <stdio.h>
  2. void p1(int);
  3. void p2(int);
  4. char *dig[] = {"零","壹","貳","參","肆","伍","陸","柒","捌","玖"};
  5. char *fer[] = {"\0","十","百","仟","萬","十","百","仟","億"};
  6. int times=0;
  7. int main()
  8. {
  9. int n;
  10. printf("N = ");
  11. scanf("%d",&n);
  12. p1(n);
  13. printf("元\n");
  14. return 0;
  15. }
  16. void p1(int n)
  17. {
  18. int prefix,curryDig;
  19. if( n < 10){
  20. printf("%s",dig[n]);
  21. p2(times);
  22. }
  23. else{
  24. prefix = n / 10;
  25. times++;
  26. p1(prefix);
  27. times--;
  28. curryDig = n % 10;
  29. if(curryDig == 0){
  30. int count = 0;
  31. while( prefix % 10 == 0){
  32. count++;
  33. prefix /= 10;
  34. times--;
  35. curryDig = prefix % 10;
  36. }
  37. if(times != 0)
  38. printf("%s",dig[0]);
  39. }
  40. else{
  41. printf("%s",dig[curryDig]);
  42. p2(times);
  43. }
  44. }
  45. }
  46. void p2(int times)
  47. {
  48. printf("%s",fer[times]);
  49. }
Success #stdin #stdout 0s 4572KB
stdin
Standard input is empty
stdout
N = 零元