K.N.King 编写的《C语言程序设计现代方法 第2版》第P68第11题 原题如下: 编写一个程序,要求用户输入一个两位数,然后显示该数的英文单词: Enter a two-digit number: 45 You entered the number forty-five. 提示:把数分解为两个数字。用一个switch语句显示第一位数字对应的单词(“twenty”、“thirty”等),用第二个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