Advertisement
NuyenTrongHa

Đọc số TV. fix lần 1

Sep 11th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4. long n,n0;
  5. int i,j,imax,A[5],B[5],idem;
  6. char DOC[10][10]={"khong","mot","hai","ba","bon","nam","sau","bay","tam","chin"};
  7. printf("nhap n ");
  8. scanf("%ld", &n);
  9. if (n==5) printf("\n So tren doc la: nam \n"); //doc so 5 rieng
  10. else
  11. { //tach thanh bo 3 chu so
  12. i=0; idem=0;
  13. while(n>0)
  14. {
  15. i+=1;
  16. A[i]=n%1000;
  17. n/=1000;
  18. }
  19. printf("\n So tren doc la: \n");
  20. if (i == 4)
  21. {
  22. printf(" %s ty",DOC[A[i]]);
  23. idem+=1;
  24. i--;
  25. } //doc tung bo 3 chu so
  26. for (;i>0;i--)
  27. if (A[i]>0)
  28. {
  29. for (j=4;j>0;j--) B[j]=0;
  30. while (A[i]>0)
  31. {
  32. j+=1;
  33. B[j]=A[i]%10;
  34. A[i]/=10;
  35. }
  36. if (idem>0 && j<3) j=3;
  37. for (;j>0;j--)
  38. {
  39. if (j==3) printf(" %s tram ",DOC[B[3]]);
  40. if (j==2)
  41. {
  42. if (B[2]==0 && B[3]*B[1]!=0) printf("linh");
  43. else if (B[2]==1) printf("muoi");
  44. else if (B[2]>1)printf(" %s muoi",DOC[B[2]]);
  45. }
  46. if (j==1)
  47. if (B[1]>0)
  48. if (i==1&&B[1]==5) printf(" lam");
  49. else printf(" %s ",DOC[B[1]]);
  50. }
  51. if (i==3) printf(" trieu");
  52. else if(i==2) printf(" nghin");
  53. idem+=1;
  54. }
  55. }
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement