当前位置:网站首页>C语言经典例题-switch case语句转换日期格式
C语言经典例题-switch case语句转换日期格式
2022-07-23 10:47:00 【Blue_lan18】
下面编写程序,用这种格式来显示日期。用户以月/日/年的格式录入日期,然后计算机显示出“法定”格式的日期:
Enter date (mm/dd/yy): 7/19/14
Dated this 19th day of July,2014.
# include <stdio.h>
int main()
{
int month, day, year;
printf("Enter date (mm/dd/yy): ");
scanf("%d/%d/%d", &month, &day, &year);
printf("Dated this %d", day);
switch(day){
case 1: case 21: case 31:
printf("st");
break;
case 2: case 22:
printf("nd");
break;
case 3: case 13: case 23:
printf("rd");
break;
default: printf("th");
break;
}
printf(" day of ");
switch(month){
case 1: printf("January"); break;
case 2: printf("February"); break;
case 3: printf("March"); break;
case 4: printf("April"); break;
case 5: printf("May"); break;
case 6: printf("June"); break;
case 7: printf("July"); break;
case 8: printf("August"); break;
case 9: printf("September"); break;
case 10: printf("October"); break;
case 11: printf("November"); break;
case 12: printf("Decembery"); break;
}
printf(", 20%.2d.\n", year);
return 0;
}

注意,%.2d用于显示年份的最后两位数字。如果用%d代替的话,那么将错误地显示倒数第二位为零的年份(将会把2001显示成201)。
边栏推荐
- STL map operation
- Part II how to design an RBAC authority system
- Six ways of uniapp route jump
- Where can I download airserver? How to use tutorial
- 7.13WEB安全作业
- 他山之石 | 阿里多模态知识图谱探索与实践
- ESP三相SVPWM控制器的simulink仿真
- Completely uninstall MySQL in centos7
- Part I basic information of the project
- Start process of activity
猜你喜欢

Error | cannot read property '_ normalized‘ of undefined

VSCode 更新后与tab相关快捷键无法使用
![[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{}](/img/d0/133d628a304f5c6b5f0d514c9fe222.jpg)
[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{}

安全作业7.22

基于matlab的BOC调制信号捕获仿真

Idea five free plug-ins to improve efficiency

338. Bit count

turbo编译码误码率性能matlab仿真

VSCode的感叹号+tab的快捷键不能用,以及A-SOUL-live2d插件出问题的解决方法

After vscode is updated, the shortcut keys related to tab cannot be used
随机推荐
STL deque
The exclamation point of vscode +tab shortcut key cannot be used, and the solution to the problem of a-soul-live2d plug-in
【机器学习基础】无监督学习(5)——生成模型
用rpm -e --nodeps进行批量删除
Solve the problem that kotlin writes the Android project compilation report execution failed for task ': app:kaptdebugkotlin'. Exception
第二篇 如何设计一个RBAC权限系统
[hiflow] regularly send Tencent cloud SMS sending group
RTA is a new way to accurately launch advertisements?
Blazor quickly realizes Minesweeper
Common SQL of Oracle Report
报错 | cannot read property ‘_normalized‘ of undefined
Matlab simulation of Turbo code error rate performance
Six ways of uniapp route jump
第一篇 项目基本情况介绍
基于simulink的双闭环矢量控制的电压型PWM整流器仿真
Deep understanding of CAS (spin lock)
力扣-单调栈
Start process of activity
【启发式分治】启发式合并的逆思想
MariaDB 数据库升级版本