C语言教程
C语言控制语句
C语言函数
C语言数组
C语言指针
C语言字符串
C语言数学函数
C语言结构
C语言文件处理
C预处理器

C语言字符转换为数字

转换字符数的方法: 在c语言中,我们可以借助循环和切换大小写轻松地转换字符数。在此程序中,我们从用户那里获取输入并迭代该数字直到它为0。在迭代过程中,我们将其除以10,然后在切换的情况下传递其余部分以获取该数字的单词。
让我们看一下c程序将数字转换为字符。
#include<stdio.h>  
#include<stdlib.h>
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  

昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4