C语言经典例题-将输入的两位数转成英文
编写一个程序,要求用户输入一个两位数,然后显示该数的英文单词:
Enter a two-digit number: 45
You entered the number forty-five.
提示:把数分解为两个数字。用一个switch语句显示第一位数字对应的单词(“twenty”、"thirty”等),用第二个switch语句显示第二位数字对应的单词。不要忘记10~19需要特殊处理。
# include <stdio.h>int main()
{int a1, a2;printf("Enter a two-digit number: ");scanf("%1d%1d", &a1, &a2);//先解决10-19 的数字if(a1 < 2){switch(a2){case 0: printf("You entered the number ten.\n"); break;case 1: printf("You entered the number eleven.\n"); break;case 2: printf("You entered the number twelve.\n"); break;case 3: printf("You entered the number thirteen.\n"); break;case 4: printf("You entered the number fourteen.\n"); break;case 5: printf("You entered the number fifteen.\n"); break;case 6: printf("You entered the number sixteen.\n"); break;case 7: printf("You entered the number seventeen.\n"); break;case 8: printf("You entered the number eighteen.\n"); break;case 9: printf("You entered the number nineteen.\n"); break;}}else{//十位数switch(a1){case 2: printf("You entered the number twenty"); break;case 3: printf("You entered the number thirty"); break;case 4: printf("You entered the number forty"); break;case 5: printf("You entered the number fifty"); break;case 6: printf("You entered the number sixty"); break;case 7: printf("You entered the number seventy"); break;case 8: printf("You entered the number eighty"); break;case 9: printf("You entered the number ninety"); break;}//个位数switch(a2){case 0: printf(".\n"); break;case 1: printf("-one.\n"); break;case 2: printf("-two.\n"); break;case 3: printf("-three.\n"); break;case 4: printf("-four.\n"); break;case 5: printf("-five.\n"); break;case 6: printf("-six.\n"); break;case 7: printf("-seven.\n"); break;case 8: printf("-eight.\n"); break;case 9: printf("-nine.\n"); break;}}return 0;}
C语言经典例题-将输入的两位数转成英文相关推荐
- C语言经典例题100道(没错,就是你要找的那个)
C语言经典例题100道(没错,就是你要找的那个) 希望可以帮助到你,加油!!! [程序1] 题目:有1.2.3.4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? 1.程序分析:可填在百位 ...
- c语言编程从键盘上输入两个整数m和n,C语言习题 求键盘输入的两个正整数的最大公约数和最小公倍数...
C语言习题 求键盘输入的两个正整数的最大公约数和最小公倍数以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! C语言习题 求 ...
- C语言经典例题100例(一)
C语言经典例题100例(程序一) 程序一 有1.2.3.4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? 解: 首先看题本身是数字相互排列且不重复问题,用循环语句就可以解决.要求输出而是 ...
- 用c语言编写:从健盘输入一个两位数的正整数 a,将其转换形成一个整数b并输出b。 转换的方式是:将a中较大的数码作为b的十位,剩余的数码作为上的个位。例如,当输入a =49,则结果 b=94...
#include <stdio.h> int main(){ int a; int b; printf("请输入一个两位数的正整数a:"); scanf("% ...
- 怎样用才c语言定义一个三位数,怎样编写一个c语言程序计算任意输入一个3位数的整数的各位数字之和。要求主函数包括输入输出和调用该函数。...
点击查看怎样编写一个c语言程序计算任意输入一个3位数的整数的各位数字之和.要求主函数包括输入输出和调用该函数.具体信息 答:#include void main(){ int a,sum=0; pri ...
- c语言经典例题及其答案详解,100个经典c语言例题(带答案)
100个经典c语言例题(带答案) 100 个经典 c 语言例题(带答案)经典C源程序 100 例- -1 经典C源程序 100 例 [程序 1]题目:有 1.2.3.4 个数字,能组成多少个互不相同且 ...
- c语言 异或_C语言经典例题来袭!5大方法告诉你答案
各位,今天我们来看一个C语言的经典例题,因为最近有不少人后台问的问题都跟这个或多或少有点关系,所以今天咱们拿出来对这类问题进行一个总结,话不多说,就问下面的代码会输出什么? #include 意图很明 ...
- c语言经典例题100例
题目:一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少? 1.程序分析:在10万以内判断,先将该数加上100后再开方,再将该数加上268后再开方,如果开方后 的 ...
- c语言 正整数 几位 逆序,c语言经典例题:正整数求位数and求顺、逆序位数
经典例题:正整数求位数and求顺.逆序位数 题目要求: 给出一个int整形正整数,要求: 1.求出它是几位数字 2.按照逆序分别输出每位数字,例如123输出为321 3.按正序输出每位数字 分析: 一 ...
最新文章
- python保存模型与参数_如何导出python中的模型参数
- 在长沙怎么挑选装饰公司
- Alpha(5/10)
- 稀疏自编码器符号一览表
- 用canvas整个打飞机游戏
- 数据结构-编程实现一个双链表的建立,双链表的打印,双链表的测长
- Linux调度系统全景指南(下篇)
- AI圣经《深度学习》作者斩获2018年图灵奖,100 万奖励!
- Java面试题及答案2019_一般JAVA面试题及答案解析2019
- PreScan第三课:Sensors Model
- Foobar2000是一款完全可定制的音乐播放器
- 模拟多线程给多用户发送短信
- java漫画pdf_Java并发编程学习宝典(漫画版)(PDF+HTML完结)
- 用电视上网——网络电视机顶盒
- 云计算成就代码之美——首届阿里云开发者大赛巡礼
- turtle递归作图绘制谢尔宾斯基地毯【详解】
- w7怎么写html代码,笔记本win7系统使用记事本编辑和运行html代码的方法
- 计算机碎片整理,如何对计算机进行碎片整理
- 流氓劫持(浏览器)、
- opencv---c++(2)