c - 在C语言中以日期为dd/mm/yy并以“合法”形式显示日期
问题描述
我的程序工作但没有完成它的任务。例如,当我输入 2020 年 12 月 11 日作为输入时,它会给出以下结果:“日期为 (null) 的第 16 天,200。”
如何解决我的代码的月份和年份部分?
#include <stdio.h>
int main()
{
int day, mon, year;
char *months[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
printf("Enter date(DD/MM/YY): ");
scanf("%d%d%d", &day, &mon, &year);
if(day%10 == 1 && day != 11)
printf("Dated this %dst day of %s, 20%d.", day, months[mon], year);
else if(day%10 == 2 && day != 12)
printf("Dated this %dnd day of %s, 20%d.", day, months[mon], year);
else if(day%10 == 3 && day != 13)
printf("Dated this %drd day of %s, 20%d.", day, months[mon], year);
else
printf("Dated this %dth day of %s, 20%d.", day, months[mon], year);
return 0;
}
解决方案
推荐阅读
- laravel - 精益雄辩的结果 ->with() 渴望加载
- python - 如何在每一行中的特定字符串之后计算文本文件中的唯一单词?
- php - Symfony Fileloader 找不到现有的类
- javascript - 处理 Flask 文件上传/下载中的编码
- html - CSS - 文本在顶部对齐,不管 flexbox 属性如何
- json - 是否可以从 newrelic 警报中获取未决事件计数
- matlab - 如何将 GUIDE 的导出工具生成的 MATLAB GUI *.m 文件转换回 *.fig 文件?
- mysql - 从 SQL 数据库中提取一个整数值用于计算
- python-3.x - 使用 Anaconda 的 Sublime 3 中的 Numpy 错误
- c# - 点网核心中的存储过程