📅  最后修改于: 2020-10-23 01:13:23             🧑  作者: Mango
字符转换:在c语言中,我们可以借助循环和切换大小写轻松地转换字符的数字。在此程序中,我们从用户那里获取输入并对该数字进行迭代,直到它为0。在迭代过程中,我们将其除以10,然后将其余部分传递给switch大小写,以获得该数字的单词。
让我们看一下c程序将字符转换为数字。
#include
#include
int main(){
long int n,sum=0,r;
system("cls");
printf("enter the number=");
scanf("%ld",&n);
while(n>0)
{
r=n%10;
sum=sum*10+r;
n=n/10;
}
n=sum;
while(n>0)
{
r=n%10;
switch(r)
{
case 1:
printf("one ");
break;
case 2:
printf("two ");
break;
case 3:
printf("three ");
break;
case 4:
printf("four ");
break;
case 5:
printf("five ");
break;
case 6:
printf("six ");
break;
case 7:
printf("seven ");
break;
case 8:
printf("eight ");
break;
case 9:
printf("nine ");
break;
case 0:
printf("zero ");
break;
default:
printf("tttt");
break;
}
n=n/10;
}
return 0;
}
输出:
enter the number=4321
four three two one