问题
在不使用 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#includeint 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(no99) 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
",firstno[no-10+1]); else if(no>=20 && no
",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语句将数字打印为单词的详细内容,更多请关注【创想鸟】其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2583884.html