您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

编写一个C程序,使用elseif语句将数字打印为单词

2026/1/9 15:45:56发布19次查看
问题在不使用 switch case 的情况下,如何使用 c 编程语言以文字形式打印给定的数字?
解决方案在此程序中,我们检查三个条件以用单词打印两位数 -
if(no99)
if(no99) p>
输入的数字不是两位数
else if(no==0)
将第一个数字打印为零
else if(no>=10 && no
用文字打印个位数
else if(no>=20 && no
     if(no%10 == 0)
用文字打印两位数
程序 现场演示
#include<stdio.h>#include<string.h>int main(){ int no; char *firstno[]={"zero","ten","eleven","twelve","thirteen", "fourteen","fifteen","sixteen","seventeen", "eighteen","nineteen"}; char *secondno[]={"twenty","thirty","forty","fifty","sixty", "seventy","eighty","ninty"}; char *thirdno[]={"one","two","three","four","five","six","seven","eight","nine"}; printf("enter a number:"); scanf("%d",&no); if(no<0 || no>99) printf("enter number is not a two digit number
"); else if(no==0) printf("the enter no is:%s
",firstno[no]); else if(no>=10 && no<=19) printf("the enter no is:%s
",firstno[no-10+1]); else if(no>=20 && no<=90) if(no%10 == 0) printf("the enter no is:%s
",secondno[no/10 - 2]); else printf("the enter no is:%s %s
",secondno[no/10-2],thirdno[no%10-1]);return 0;}
输出enter a number:79the enter no is: seventy nineenter a number:234enter number is not a two digit number
以上就是编写一个c程序,使用elseif语句将数字打印为单词的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product