Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C by trang ( 5 years ago )
#include<stdio.h>
#include<math.h>
void nhap(int &n)
{
printf("\n nhap vao mot so : ");
scanf("%d", &n);
printf("\n");
}
void docmotchuso(int n);
void dochaichuso(int n);
void docbachuso(int n);
void tachso(int n)
{
// vidu 123,456,789 --> co 9 chu so va co 3 cum
int soluongchuso = (int)log10((double)n) + 1; // == 9
int sodauphay = (soluongchuso - 1) / 3; // == 2
printf("\nso luong chu so %d la %d", n, soluongchuso);
printf("\n\n");
for(int i = sodauphay ; i >= 0 ; i--) // bi sai dieu kien bao sao k chay vong lap duoc
{
int temp = n;
temp /= pow(10.0,(3 * i)); // ==> 123 = 123,456,789 / 10^(3*i)
int sochusobientemp = (int)log((double)temp) + 1; // =3 =2 =1
if(sochusobientemp = 1)
{
docmotchuso(temp);
}
if(sochusobientemp = 2)
{
dochaichuso(temp);
}
if(sochusobientemp = 3)
{
docbachuso(temp);
}
n = n % (int)pow(10.0,(3*i)); // == 456,789
int chusoconlai = (int)log10((double)n) + 1;
if(chusoconlai == 3) // 123,221
{
printf(" nghin ");
}
if(chusoconlai == 6) // 1,123,456
{
printf(" trieu ");
}
if(chusoconlai == 9) // 3,345,345,234
{
printf(" ty ");
}
if(chusoconlai == 12) // 1,123,123,456,345
{
printf(" nghin ");
}
}
}
void docmotchuso(int n)
{
int tem = n;
if(tem == 1)
printf(" mot ");
else if(tem == 2)
printf(" hai ");
else if(tem == 3)
printf(" ba ");
else if(tem == 4)
printf(" bon ");
else if(tem == 5)
printf(" nam ");
else if(tem ==6)
printf(" sau ");
else if(tem == 7)
printf(" bay ");
else if(tem == 8)
printf(" tam ");
else if(tem == 9)
printf(" chin ");
}
void dochaichuso(int n) // 12 23 35 56
{
int tem = n;
tem /= 10; // = 1
if(tem == 1)
printf(" muoi ");
else if(tem == 2)
printf(" hai muoi ");
else if(tem == 3)
printf(" ba muoi ");
else if(tem == 4)
printf(" bon muoi ");
else if(tem == 5)
printf(" nam muoi ");
else if(tem ==6)
printf(" sau muoi ");
else if(tem == 7)
printf(" bay muoi ");
else if(tem == 8)
printf(" tam muoi ");
else if(tem == 9)
printf(" chin muoi ");
tem = n % 10; // = 2
if(tem == 1)
printf(" mot ");
else if(tem == 2)
printf(" hai ");
else if(tem == 3)
printf(" ba ");
else if(tem == 4)
printf(" bon ");
else if(tem == 5)
printf(" lam ");
else if(tem ==6)
printf(" sau ");
else if(tem == 7)
printf(" bay ");
else if(tem == 8)
printf(" tam ");
else if(tem == 9)
printf(" chin ");
}
void docbachuso(int n)
{ //123 213 512 515
int tem = n;
tem /= 100; // =1 =2 =5 =3
if(tem == 1)
printf(" mot tram ");
else if(tem == 2)
printf(" hai tram ");
else if(tem == 3)
printf(" ba tram ");
else if(tem == 4)
printf(" bon tram ");
else if(tem == 5)
printf(" nam tram ");
else if(tem ==6)
printf(" sau tram ");
else if(tem == 7)
printf(" bay tram ");
else if(tem == 8)
printf(" tam tram ");
else if(tem == 9)
printf(" chin tram ");
int m = n % 100; // = 23 =13
dochaichuso(m);
}
int main()
{
int n;
nhap(n);
tachso(n);
return 0;
}
Revise this Paste