fork(1) download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. char oneDigit[][10] = {"Khong", "Mot", "Hai", "Ba", "Bon", "Nam", "Sau", "Bay", "Tam", "Chin"};
  5. char base[][10] = {"", "Muoi", "Tram", "Nghin", "Muoi", "Tram", "Trieu", "Muoi", "Tram", "Ty", "Muoi", "Tram", "Nghin"};
  6.  
  7. void d2w(int a) {
  8. if (a < 10) {
  9. printf("%s ", oneDigit[a]);
  10. return;
  11. }
  12. int s[100] = {0};
  13. int i = 0;
  14. while (a > 0) {
  15. s[i++] = a % 10;
  16. a /= 10;
  17. }
  18. for (int j = i - 1; j >= 0; j--) {
  19. if (!strcmp(oneDigit[s[j]], "Khong") && !strcmp(base[j], "Muoi") && s[j - 1] != 0)
  20. printf("Linh ");
  21. else if (!strcmp(oneDigit[s[j]], "Mot") && !strcmp(base[j], "Muoi"))
  22. printf("Muoi ");
  23. else if (s[j] != 0 || !strcmp(base[j], "Tram")) {
  24. printf("%s ", oneDigit[s[j]]);
  25. printf("%s ", base[j]);
  26. } else if ((j % 3 == 0) && (s[j + 1] != 0 || s[j + 2] != 0))
  27. printf("%s ", base[j]);
  28. }
  29. }
  30.  
  31. int main() {
  32. int n = 0;
  33. while (1) {
  34. printf("Enter an integer number: ");
  35. scanf("%d", &n);
  36. printf("%d in word is: ", n);
  37. d2w(n);
  38. printf("\n\nDo you want continue:\n");
  39. printf("1. Yes\n0. No\n");
  40. while (getchar()!='\n');
  41. if (getchar() == '0')
  42. break;
  43. }
  44. return 0;
  45. }
  46.  
Success #stdin #stdout 0s 9424KB
stdin
100305
1
503201469
0
stdout
Enter an integer number: 100305 in word is: Mot Tram Nghin Ba Tram Linh Nam  

Do you want continue:
1. Yes
0. No
Enter an integer number: 503201469 in word is: Nam Tram Linh Ba Trieu Hai Tram Linh Mot Nghin Bon Tram Sau Muoi Chin  

Do you want continue:
1. Yes
0. No