kiem tien, kiem tien online, kiem tien truc tuyen, kiem tien tren mang
Friday, September 26, 2014

chương trình đọc một số có 4 chữ số trong lập trình c

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i, a[4];
printf("nhap so co 4 chu so: ");
scanf_s("%d", &n);
if (n > 999 && n < 10000)
{
printf("doc la             : ");
for (i = 0; i < 4; i++)
{
a[i] = n % 10;
n = n / 10;
}
switch (a[3])
{
case 1:printf(" mot "); break;
case 2:printf(" hai "); break;
case 3:printf(" ba "); break;
case 4:printf(" bon "); break;
case 5:printf(" nam "); break;
case 6:printf(" sau "); break;
case 7:printf(" bay "); break;
case 8:printf(" tam "); break;
case 9:printf(" chin "); break;
}
printf(" nghin ");
switch (a[2])
{
case 1:printf(" mot "); break;
case 2:printf(" hai "); break;
case 3:printf(" ba "); break;
case 4:printf(" bon "); break;
case 5:printf(" nam "); break;
case 6:printf(" sau "); break;
case 7:printf(" bay "); break;
case 8:printf(" tam "); break;
case 9:printf(" chin "); break;
case 0:printf(" khong "); break;
}
printf(" tram ");
switch (a[1])
{
case 1:printf(" mot muoi "); break;
case 2:printf(" hai muoi "); break;
case 3:printf(" ba muoi "); break;
case 4:printf(" bon muoi "); break;
case 5:printf(" nam muoi "); break;
case 6:printf(" sau muoi "); break;
case 7:printf(" bay muoi "); break;
case 8:printf(" tam muoi "); break;
case 9:printf(" chin muoi "); break;
case 0:printf(" le "); break;
}
switch (a[0])
{
case 1:printf(" mot \n"); break;
case 2:printf(" hai \n"); break;
case 3:printf(" ba \n"); break;
case 4:printf(" bon \n"); break;
case 5:if (a[1] == 0) printf(" nam \n");
  else printf(" lam \n"); break;
case 6:printf(" sau \n"); break;
case 7:printf(" bay \n"); break;
case 8:printf(" tam \n"); break;
case 9:printf(" chin \n"); break;
}
}
else printf("nhap so khong dung");
_getch();
}

0 comments:

Post a Comment

domain, domain name, premium domain name for sales

Popular Posts