網(wǎng)站首頁 編程語言 正文
題目描述:輸入年份和這一年的第幾天,輸出具體的年、月、日的信息。(注意閏年的判斷!)
輸入要求:輸入兩個整數(shù)分別代表年份和這一年的第幾天。(假設數(shù)據(jù)都在有效范圍內(nèi))
輸出要求:輸出對應的年、月、日。輸出的數(shù)字之間以一條橫線間隔,輸出完畢換行。
代碼如下:
#include<stdio.h>
//接口定義,year為年,date為天數(shù),*nmonth是計算得出的月,*nday是計算得出的日
void month_day(int year, int date, int* nmonth, int* nday) {
?? ?int yu, hao;
?? ?int wang[2][13] = {
?? ??? ?{0,31,28,31,30,31,30,31,31,30,31,30,31},
?? ??? ?{0,31,29,31,30,31,30,31,31,30,31,30,31},?? ??? ??? ??? ??? ??? ?//定義數(shù)組存放閏年和平年的天數(shù)
?? ?};
?? ?hao = (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;?? ??? ?//閏年判別條件
?? ?for (yu = 1; date > wang[hao][yu]; yu++)
?? ??? ?date -= wang[hao][yu];
?? ?*nmonth = yu;
?? ?*nday = date;
}
int main() {
?? ?int day, month, year, date;?? ??? ??? ??? ??? ??? ??? ??? ?//定義日、月、年和天數(shù)的變量
?? ?printf("請輸入年份和第幾天:\n");
?? ?scanf_s("%d%d", &year, &date);
?? ?if (date >= 1 && year >= 1) {
?? ??? ?if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0 && date < 367) {
?? ??? ??? ?month_day(year, date, &month, &day);
?? ??? ??? ?printf("具體年、月、日如下:\n%d-%d-%d", year, month, day);
?? ??? ?}
?? ??? ?if (year % 4 != 0 && date < 366) {
?? ??? ??? ?month_day(year, date, &month, &day);
?? ??? ??? ?printf("具體年、月、日如下:\n%d-%d-%d", year, month, day);
?? ??? ?}
?? ?}
?? ?else {
?? ??? ?printf("搞事情是吧?這邊給你強行退出!\n");
?? ?}
?? ?return 0;
}
原文鏈接:https://blog.csdn.net/weixin_67793168/article/details/125919329
相關推薦
- 2022-07-22 URLClassLoader加載Class時的類初始化問題
- 2022-09-29 Kotlin協(xié)程Dispatchers原理示例詳解_Android
- 2022-04-20 python數(shù)據(jù)類型中的字符串你了解多少_python
- 2022-07-21 hadoop本地數(shù)據(jù)統(tǒng)計
- 2022-06-04 Jenkins初級應用Publish?Over?SSH插件配置_安裝教程
- 2023-07-14 react 利用插件react-draggable實現(xiàn)拖拽功能
- 2023-01-11 Pytorch如何把Tensor轉(zhuǎn)化成圖像可視化_python
- 2022-12-30 Golang通道channel的源碼分析_Golang
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支