当前位置:网站首页>C语言经典例题-将输入的两位数转成英文
C语言经典例题-将输入的两位数转成英文
2022-07-23 10:47:00 【Blue_lan18】
编写一个程序,要求用户输入一个两位数,然后显示该数的英文单词:
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;
}
边栏推荐
猜你喜欢

Xlswriter - Excel export

多线程一定能优化程序性能吗?

Les raccourcis clavier liés à l'onglet ne peuvent pas être utilisés après la mise à jour du vscode
![[pyGame practice] playing poker? Win or lose? This card game makes me forget to eat and sleep.](/img/ba/a174c5daccef7a6ea72c11dad8601d.png)
[pyGame practice] playing poker? Win or lose? This card game makes me forget to eat and sleep.

基于matlab的BOC调制解调的同步性能仿真,输出跟踪曲线以及不同超前滞后码距下的鉴别曲线

Use of RSA encryption

Six ways of uniapp route jump

Batch deletion with RPM -e --nodeps
![[CTFHub]JWT 的头部和有效载荷这两部分的数据是以明文形式传输的,如果其中包含了敏感信息的话,就会发生敏感信息泄露。试着找出FLAG。格式为 flag{}](/img/d0/133d628a304f5c6b5f0d514c9fe222.jpg)
[CTFHub]JWT 的头部和有效载荷这两部分的数据是以明文形式传输的,如果其中包含了敏感信息的话,就会发生敏感信息泄露。试着找出FLAG。格式为 flag{}

易基因|靶基因DNA甲基化测序(Target-BS)
随机推荐
Find a specific number in an ordered array (binary search or half search)
Part III detailed explanation of RBAC authority management database design
基于PSO优化的多目标最优值求解matlab仿真
查找论文源代码
[solve the exception] Flink uploads the jar package to the cluster environment, and the operation report does not serialize the exception
centos7 中彻底卸载mysql
报错 | cannot read property ‘_normalized‘ of undefined
安全作业7.22
Xlswriter - Excel export
[machine learning basics] unsupervised learning (5) -- generation model
pytorch opencv pil图像预处理比较
Safety 7.18 operation
VMware虚拟机下载安装使用教程
The current situation and history of it migrant workers
uniapp路由跳转的六种方式
Full backpack!
[ctfhub] the data of JWT header and payload are transmitted in clear text. If sensitive information is contained in it, sensitive information will be leaked. Try to find the flag. Format is flag{}
Clickhouse, let the query fly!!!
Simulation of voltage source PWM rectifier with double closed loop vector control based on Simulink
ClickHouse,让查询飞起来!!!