当前位置:网站首页>Classic example of C language - convert the input two digits into English
Classic example of C language - convert the input two digits into English
2022-07-24 00:26:00 【Blue_ lan18】
Write a program , Ask the user to enter a two digit number , Then show the number of English words :
Enter a two-digit number: 45
You entered the number forty-five.
Tips : Break down a number into two numbers . Use one switch Statement displays the word corresponding to the first digit (“twenty”、"thirty” etc. ), In the second switch Statement displays the word corresponding to the second digit . Don't forget it 10~19 Require special treatment .
# include <stdio.h>
int main()
{
int a1, a2;
printf("Enter a two-digit number: ");
scanf("%1d%1d", &a1, &a2);
// Solve first 10-19 The number of
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{
// Ten digits
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;
}
// Single digit
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;
}
边栏推荐
- Redis数据结构
- Tencent cloud was affirmed by international professional streaming media evaluation: video coding performance is the best in all three scenarios
- Pytest interface automation test framework | summary
- English语法_指示代词 - So
- Gbase 8C system table information function (I)
- Redis persistence mechanism RDB, AOF
- The implementation in Oracle replaces the specified content of the specified column with the desired content
- Gbase 8C access authority query function (I)
- 数据标准详细概述-2022
- MySQL client to server character set conversion
猜你喜欢
随机推荐
GBase 8c 模式可见性查询函数(一)
July 23, 2022 - mapper file description
Pytest interface automated test framework | pytest generates simple test reports
[video game training] non contact object size and shape measurement 2020 video game G
paypal订阅流程及api请求
Application of encryption technology
docker搭建sonarqube,mysql5.7环境
Docker pulls the redis image and runs it
The prediction of domestic AI protein structure reproduced a breakthrough and solved the 3D structure with a single sequence. Peng Jian's team: "the last piece of puzzle since alphafold2 has been comp
Adaptation scheme of large screen visualization
【电赛训练】非接触物体尺寸形态测量 2020年电赛G题
Try new methods
Redis cluster hash sharding algorithm (slot location algorithm)
PHP implements stripe subscription
Delete all data of specified query criteria in Oracle
English grammar_ Demonstrative pronoun -such / the same
AWS Part 4 one machine and one secret
Flutter | firstwhere error reporting
win10下基于anaconda的detectron2安装
Detailed overview of data standards -2022








