Advertisement
Guest User

Câu 5: Viết chương trình đọc 1 số nguyên dương n có kiểu int

a guest
Feb 22nd, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. string read(int value)
  5. {
  6.     switch(value)
  7.     {
  8.         case 0:
  9.             return "";
  10.             break;
  11.         case 1:
  12.             return "mot";
  13.             break;
  14.         case 2:
  15.             return "hai";
  16.             break;
  17.         case 3:
  18.             return "ba";
  19.             break;
  20.         case 4:
  21.             return "bon";
  22.             break;
  23.         case 5:
  24.             return "nam";
  25.             break;
  26.         case 6:
  27.             return "sau";
  28.             break;
  29.         case 7:
  30.             return "bay";
  31.             break;
  32.         case 8:
  33.             return "tam";
  34.             break;
  35.         case 9:
  36.             return "chin";
  37.             break;
  38.            
  39.     }
  40. }
  41. void toText(int x)
  42. {
  43.     int temp = x;
  44.     int x1 = temp % 10;
  45.     temp = temp / 10;
  46.     int x2 = temp % 10;
  47.     temp = temp / 10;
  48.     int x3 = temp % 10;
  49.     temp = temp / 10;
  50.     int x4 = temp % 10;
  51.     temp = temp / 10;
  52.     int x5 = temp % 10;
  53.     temp = temp / 10;
  54.     int x6 = temp % 10;
  55.     temp = temp / 10;
  56.     int x7 = temp % 10;
  57.     temp = temp / 10;
  58.     int x8 = temp % 10;
  59.     temp = temp / 10;
  60.     int x9 = temp % 10;
  61.     temp = temp / 10;
  62.     int x10 = temp % 10;
  63.     string t1 = read(x1);
  64.     string t2 = read(x2);
  65.     string t3 = read(x3);
  66.     string t4 = read(x4);
  67.     string t5 = read(x5);
  68.     string t6 = read(x6);
  69.     string t7 = read(x7);
  70.     string t8 = read(x8);
  71.     string t9 = read(x9);
  72.     string t10 = read(x10);
  73.     if (x1 == 0 && x2 == 0 &&  x3 == 0 && x4 == 0 && x5 == 0 && x6 == 0 && x7 == 0 &&  x8 == 0 && x9 == 0 && x10 == 0) cout << "Khong";
  74.    
  75.     //ty
  76.     if (x10 != 0)
  77.     {
  78.         cout << t10;
  79.         cout << " ty ";
  80.     }
  81.    
  82.     //Trieu
  83.     if (x9 == 0 && x10 == 0) cout << "";
  84.     else if (x9 == 0 && (x8 != 0 || x7 != 0)) cout << "khong tram ";
  85.     else if (x9 != 0)
  86.     {
  87.         cout << t9 << " ";
  88.         cout << "tram ";
  89.     }
  90.     if (x8 == 1) cout << "muoi ";
  91.     else if(x8 != 0)
  92.     {
  93.         cout << t8 << " ";
  94.         cout << "muoi ";
  95.     }
  96.     if (x8 == 0 && x7 != 0 && x > 100000000) cout << "linh ";
  97.     if (x7 != 0) cout << t7 << " ";
  98.     if (x7 != 0 || x8 != 0 || x9 != 0) cout << "trieu ";
  99.    
  100.    
  101.     //Nghin
  102.     if (x10 == 0 && x9 == 0 && x8 == 0 && x7 == 0 && x6 == 0) cout << "";
  103.     else if (x6 == 0 && (x5 != 0 || x4 != 0)) cout << "khong tram ";
  104.     else if (x6 != 0)
  105.     {
  106.         cout << t6 << " ";
  107.         cout << "tram ";
  108.     }
  109.     if (x5 == 1) cout << "muoi ";
  110.     else if (x5 != 0)
  111.     {
  112.         cout << t5 << " ";
  113.         cout << "muoi ";
  114.     }
  115.     if (x5 == 0 && x4 != 0 && x > 100000) cout << "linh ";
  116.     if (x4 != 0) cout << t4 << " ";
  117.     if (x6 != 0 || x5 != 0 || x4 != 0) cout << "nghin ";
  118.    
  119.    
  120.    
  121.     //Tram
  122.     if (x10 == 0 && x9 == 0 && x8 == 0 && x7 == 0 && x6 == 0 && x5 == 0 && x4 == 0 && x3 == 0) cout << "";
  123.     else if (x3 == 0 && (x2 != 0 || x1 != 0)) cout << "khong tram ";
  124.     else if (x3 != 0)
  125.     {
  126.         cout << t3 << " ";
  127.         cout << "tram ";
  128.     }
  129.    
  130.     //Chuc
  131.     if (x2 == 1) cout << "muoi ";
  132.     else if(x2 != 0)
  133.     {
  134.         cout << t2 << " ";
  135.         cout << "muoi ";
  136.     }
  137.    
  138.     //Don vi
  139.     if (x > 100 && x2 == 0) cout << "linh ";
  140.     cout << t1 << " ";
  141. }
  142. int main()
  143. {
  144.     toText(1000000001);
  145.     return 0;
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement