数字的两种读法

数字每一位按英文读与整体按英文读

编写程序:
(1) 请求用户输入正整数,整数值应小于1000,大于0。
(2) 编写一个convertIntToWords(int value)函数,它将传递的值转换为单词,并输出单词。例如,13得到“one three”,895得到“eight nine five”。
(3) 然后编写一个新的函数convertIntToRealWords(int value),它将传递的值转换为我们真正说的单词。例如,13是“thirteen”而不是“one three”,895读作“eight hundred ninety five”,而不是“eight nine five”。
(4) 在main()函数中分别调用这两个函数
(5) 用1,12,20,123,100,102,520作为输入的正整数来测试你的程序。

/*Name:programme4.cAuthor:祁麟Copyright:BJTU | school of softwareDate:2020/10/27 Description:write a function convertIntToRealWords(int value), which converts the passed value to words as we really say them.
*/#include<stdio.h>int main(void){int number;printf("退出请输入0"); while(1){printf("\n请输入一个大于0小于1000的数字: ");scanf("%d",&number);if (number==0) break;printf("\n这个数字读作:");convertIntToWords(number);printf("\n其实也可以这样读:");convertIntToRealWords(number);printf("\n厉害吧!\n"); }
return 0;
}//将1~999的数字分别转换为单词
int convertIntToWords(int value){int hundreds=0,tens=0,units=0;hundreds=value/100;tens=value%100/10;units=value-100*hundreds-tens*10;if (hundreds!=0){switch (hundreds){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;  }switch (tens){case 0:printf("zero ");break;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;}switch (units){case 0:printf("zero");break;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;}}if (hundreds==0&&tens!=0) {switch (tens){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;}switch (units){case 0:printf("zero");break;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;}}if (hundreds==0&&tens==0){switch (units){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;}}}//将1~999的数字转换为英文单词
int convertIntToRealWords(int value){int hundreds=0,tens=0,units=0;    hundreds=value/100;//得出百位上的数字 tens=value%100/10;//得出十位上的数字 units=value-100*hundreds-tens*10;//得出个位上的数字 //1到10的数 if(hundreds==0&&tens==0){switch(units){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;}     }//整百的数 if (hundreds!=0&&tens==0&&units==0){switch(hundreds){case(1) :printf("one hundred");break;case(2) :printf("two hundred");break;case(3) :printf("three hundred");break;case(4) :printf("four hundred");break;case(5) :printf("five hundred");break;case(6) :printf("six hundred");break;case(7) :printf("seven hundred");break;case(8) :printf("eight hundred");break;case(9) :printf("nine hundred");break;}}//10到100之间的数 if (value>10&&value<100){switch(tens){case 2:printf("twenty ");break;case 3:printf("thirty ");break;case 4:printf("forty ");break;case 5:printf("fifty ");break;case 6:printf("sixty ");break;case 7:printf("seventy ");break;case 8:printf("eighty ");break;case 9:printf("ninty ");break;case 1:if(units==1){printf("eleven"); break;}else if (units==2){printf("twelve"); break;}else if(units==3){printf("thirteen");    break;}else if(units==4){printf("forteen");  break;}else if(units==5){printf("fifteen");     break;}else if(units==6){printf("sixteen");      break;}else if(units==7){printf("seventeen");  break;}else if(units==8){printf("eighteen");break;}else if(units==9){printf("ninteen");break;}else{printf("ten");break;}}if(tens!=1){switch(units){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;}        }}//100~999之间的数 if (value>100&&value<1000){if(tens==0&&units!=0){//如果十位为零,个位不为零,如102 switch(hundreds){case(1) :printf("one hundred and ");break;case(2) :printf("two hundred and ");break;case(3) :printf("three hundred and ");break;case(4) :printf("four hundred and ");break;case(5) :printf("five hundred and ");break;case(6) :printf("six hundred and ");break;case(7) :printf("seven hundred and ");break;case(8) :printf("eight hundred and ");break;case(9) :printf("nine hundred and ");break;}switch(units){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;}}if(tens!=0&&units!=0){//如果十位数与个位数均不为零 switch(hundreds){case(1) :printf("one hundred ");break;case(2) :printf("two hundred ");break;case(3) :printf("three hundred ");break;case(4) :printf("four hundred ");break;case(5) :printf("five hundred ");break;case(6) :printf("nin hundred ");break;case(7) :printf("one hundred ");break;case(8) :printf("one hundred ");break;case(9) :printf("one hundred ");break;}switch(tens){case(1) :printf("and ");break;case(2) :printf("twenty ");break;case(3) :printf("thirty ");break;case(4) :printf("forty ");break;case(5) :printf("fifty ");break;case(6) :printf("sixty ");break;case(7) :printf("seventy ");break;case(8) :printf("eighty ");break;case(9) :printf("ninety ");break;}if (tens==1){//若十位数为1,如111 switch(units){case(1) :printf("eleven");break;case(2) :printf("twelve");break;case(3) :printf("thirteen");break;case(4) :printf("fourteen");break;case(5) :printf("fifteen");break;case(6) :printf("sixteen");break;case(7) :printf("seventeen");break;case(8) :printf("eighteen");break;case(9) :printf("nineteen");break;}}else switch(units){// 若十位数不为1和0,个位数不为零 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;}                 }if(tens!=0&&units==0){//若十位不为零个位为0 switch(hundreds){case(1) :printf("one hundred and ");break;case(2) :printf("two hundred and ");break;case(3) :printf("three hundred and ");break;case(4) :printf("four hundred and ");break;case(5) :printf("five hundred and ");break;case(6) :printf("nin hundred and ");break;case(7) :printf("one hundred and ");break;case(8) :printf("one hundred and ");break;case(9) :printf("one hundred and ");break;}switch(tens){case 1:printf("ten");break;case 2:printf("twenty");break;case 3:printf("thirty");break;case 4:printf("forty");break;case 5:printf("fifty");break;case 6:printf("sixty");break;case 7:printf("seventy");break;case 8:printf("eighty");break;case 9:printf("ninty");break;            }}  }
}

运行截图:

C语言入门 -- 数字的两种读法(2021/1/7)相关推荐

  1. C语言判断素数的两种方法

    C语言判断素数的两种方法 素数又称质数.所谓素数是指除了 1 和它本身以外,不能被任何整数整除的数,例如17就是素数,因为它不能被 2~16 的任一整数整除. 思路1):因此判断一个整数m是否是素数, ...

  2. 【❗划重点!C语言函数参数传递只有两种方式(值传递,地址传递),不支持“引用传递”!❗】

    引子 上篇文章<C语言函数传参の结构体数组篇>提到了C语言的函数参数传递方式,百度了一一一大圈,有说两种的,也有说三种的,简直把我搞晕了,"值传递和地址传递"是毫无疑问 ...

  3. 从用户的角度看 c语言中函数有两种,【南开大学】20秋学期(1709、1803、1809、1903、1909、2003、2009 )《C语言程序设计》在线作业答卷...

    20秋学期(1709.1803.1809.1903.1909.2003.2009 )<C语言程序设计>在线作业 试卷总分:100  得分:100 一.单选题 (共 40 道试题,共 80 ...

  4. zookeeper快速入门——应用(两种分布式锁)

    在<zookeeper快速入门--简介>一文中,我们介绍了zookeeper的机制.但是还是比较抽象,没有直观感受到它在分布式系统中的应用.本文我们使用一个例子,三次迭代演进,来说明Zoo ...

  5. c语言作用域有哪两种变量,2017年计算机二级C语言字考点归纳:变量的存储类别、作用域及生存期...

    7.7 变量的存储类别.作用域及生存期 1.变量的存储类别 在C语言中,有两类存储类别:自动类别及静态类别. 有4个与两种存储类别有关的说明符:auto(自动).register(寄存器).stati ...

  6. python入门——Python的两种编程语言:交互式和文件式

    文章目录 一.Python的两种编程语言 1. 交互式 2. 文件式 以下内容来自于中国慕课网中<零基础学Python语言CAP>课程的学习笔记. 一.Python的两种编程语言 1. 交 ...

  7. C语言动态数组的两种定义方式

      动态内存分配具有非常多的好处,可以最大化的节约内存空间的大小.本文将通过两种方式来实现C语言中内存的动态分配,希望你看完本文后能有所收获. 一.直接对数组大小进行输入 在C99标准中C语言数组已支 ...

  8. C语言形式参数传递的两种方式

    C语言中实际参数(实参)与形式参数(形参)之间的传递方式有传值和传地址两种函数调用方式. 1.直接传值. 直接传值,在fun函数里面改变a,b的值,不会改变主函数里面a,b的值. #include&l ...

  9. C语言中字符串的两种定义方式

    我们知道C语言中是没有字符串这种数据类型的,我们只能依靠数组进行存储,即字符数组,而我们定义并且初始化数组有两种方式.下面将给大家介绍这两种方式并且介绍这两种方式的区别: 方式1 前两种是正确的定义方 ...

最新文章

  1. Charles是mac的iddler抓包工具
  2. 第三讲,我们来谈谈:“二进制的负数”
  3. python函数 一
  4. Linux如何访问mmio空间,一文读懂Linux下如何访问I/O端口和I/O内存
  5. 修改数据表部分字段方法封装-及-动态生成对象并动态添加属性
  6. 数据库---事务(一)
  7. 晶圆代工28nm制程市场动向
  8. 即将上线的Kafka 集群(用CM部署的)无法使用“--bootstrap-server”进行消费,怎么破?...
  9. 俄罗斯国家黑客TA505被指攻击金融机构
  10. No package ‘libpeas-1.0‘ found/No package ‘libpeas-gtk-1.0‘
  11. 【工具推荐】之桌面软件
  12. Java学习笔记(十)——开发个小项目(GoBang2.0)
  13. 运行 Clojure 编程实战 5.3 节代码出现 Could not locate Clojure resource on classpath 问题
  14. java调用python库pyd_Java怎么调用pyd文件
  15. JavaSrcipt学习(学习打卡Day8)
  16. 21cn邮箱服务器,21cn邮箱客户端
  17. 推荐一个基于 SpringCloud 设计精良的网上商城
  18. keil5(MDK5)配置S3C2440裸机开发调试环境
  19. [初级前端工程师]网络相关知识
  20. 创建自己免费的论坛、博客网站

热门文章

  1. 【内排序 -- 八大排序】
  2. HDU-1045 Fire Net(最大碉堡数)
  3. wgt文件怎么安装到手机_wgt是什么文件格式,wgt扩展名文件如何打开?
  4. 【Python爬虫】403 Forbidden
  5. ansible架构、安装、简单的使用
  6. android无法监听焦点,android tv常见问题(二)如何监听ViewGroup子View的焦点状态
  7. [Python]_[初级]_[多线程下载单个文件]
  8. 可能是全网唯一一个基于windows和java的关于selenium webDriver绕过网站反爬服务的方法
  9. MM 委外加工(Subconctracting)流程
  10. 智能网联云控平台在园区自动驾驶的场景应用