编写一个程序,要求用户输入一个两位数,然后显示该数的英文单词

时间:2022-05-20 03:50:22 阅读: 最新文章 文档下载
说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。
K.N.King 编写的《C语言程序设计现代方法 2版》第P6811

原题如下:

编写一个程序,要求用户输入一个两位数,然后显示该数的英文单词: Enter a two-digit number: 45 You entered the number forty-five.

提示:把数分解为两个数字。用一个switch语句显示第一位数字对应的单词(twentythirty”等),用第二个switch语句显示第二位数字对应的单词。不要忘记11~19需要特殊处理。

注:本题是针对C语言刚起步的读者的编程题目,本人也是C语言刚起步半个月的新手,自己尝试解决这道题目,写的程序可能比较混乱、不简洁,望谅解。




#include int main (void) {

int a,b;

printf("Enter a two-dight number: "); scanf("%1d%1d",&a,&b);

printf("You entered the number "); if (a!=1) {

switch (a){

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;} switch (b){

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;} } else {

switch (b){

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("ninteen.");break;} }


return 0; }




本文来源:https://www.wddqw.com/doc/57b3d962e87101f69f319559.html