编写一个C程序以使用elseif语句打印单词中的数字
问题
在不使用开关盒的情况下,如何使用C编程语言以单词的形式打印给定的数字?
解决方案
在此程序中,我们正在检查三个条件以用字打印两位数字-
if(否<0||否>99)
输入的数字不是两位数
否则if(no==0)
将第一个数字打印为零
否则if(no>=10&&no<=19)
用字打印单位数字
否则if(no>=20&&no<=90)
如果(否%10==0)
用字打印两位数
程序
#include输出结果#include 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("输入一个数字:"); scanf("%d",&no); if(no<0 || no>99) printf("enter number is not a two digit number\n"); else if(no==0) printf("the enter no is:%s\n",firstno[no]); else if(no>=10 && no<=19) printf("the enter no is:%s\n",firstno[no-10+1]); else if(no>=20 && no<=90) if(no%10 == 0) printf("the enter no is:%s\n",secondno[no/10 - 2]); else printf("the enter no is:%s %s\n",secondno[no/10-2],thirdno[no%10-1]); return 0; }
输入一个数字:79 the enter no is: seventy nine 输入一个数字:234 enter number is not a two digit number
热门推荐
10 生日祝福语宿舍舍友 简短
11 六一祝福语简短十六字
12 新婚宴祝福语简短大全
13 女儿生日祝福语英语简短
14 陈震离职祝福语简短
15 喜得孙子祝福语简短唯美
16 幼师离别祝福语老师简短
17 新婚贺词祝福语创意简短
18 毕业教师花语祝福语简短