当前位置:网站首页>编程训练7-日期转换问题
编程训练7-日期转换问题
2022-06-26 08:32:00 【宇称不守恒4.0】
试题描述
按如下函数原型用函数编程解决如下的日期转换问题(要求考虑闰年的问题):
输入某年某月某日,计算并输出它是这一年的第几天。
/* 函数功能:对给定的某年某月某日,计算并返回它是这一年的第几天
函数参数:整型变量year、month、day,分别代表年、月、日
函数返回值:这一年的第几天*/
int DayofYear(int year, int month, int day);
输入
输入3个整数,分别代表年、月、日,相邻两项之间用一个空格隔开。
输出
输出一个整数,代表该日期是这一年的第几天。
输入示例
2000 1 31
输出示例
31
#include <stdio.h>
int DayofYear(int year, int month, int day)
{
int i,leap,n=0,a[12]={31,28,31,30,31,30,31,31,30,31,30,31};
leap=(year%4==0&&year%100!=0)||year%400==0;
for(i=0;i<month-1;i++)
n=n+a[i];
if(month>2)
n=n+leap;
return n+day;
}
int main()
{
int n,year,month,day;
scanf("%d%d%d",&year,&month,&day);
n=DayofYear(year,month,day);
printf("%d",n);
return 0;
边栏推荐
- Speckle denoising method for ultrasonic image
- WBC learning notes (II): practical application of WBC control
- Golang JSON unsupported value: Nan processing
- Convex optimization of quadruped
- Fourier transform of image
- Jupyter的安装
- 在同花顺开户证券安全吗,
- Checkerboard generation + camera calibration + stereo matching
- 1.20 study univariate linear regression
- Convert verification code image to tfrecord file
猜你喜欢

Relationship extraction --tplinker

Isinstance() function usage

Polka lines code recurrence
![[unity mirror] use of networkteam](/img/b8/93f55d11ea4ce2c86df01a9b03b7e7.png)
[unity mirror] use of networkteam

Application of wireless charging receiving chip xs016 coffee mixing cup

Line detection_ nanyangjx

框架跳转导致定位失败的解决方法

Playing card image segmentation

Relationship extraction --r-bert

Optimize quiver function in MATLAB to draw arrow diagram or vector diagram (1) -matlab development
随机推荐
STM32 project design: smart door lock PCB and source code based on stm32f1 (4 unlocking methods)
The solution of positioning failure caused by framework jump
XSS 跨站脚本攻击
多台三菱PLC如何实现无线以太网高速通讯?
leetcode2022年度刷题分类型总结(十二)并查集
Leetcode: array fast and slow pointer method
static const与static constexpr的类内数据成员初始化
isinstance()函数用法
框架跳转导致定位失败的解决方法
1.26 pytorch learning
Partial summary of 45 lectures on geek time MySQL
Detailed process of generating URDF file from SW model
Learn signal integrity from zero (SIPI) - (1)
Ltp-- extract time, person and place
ROS learning notes (5) -- Exploration of customized messages
Exploration of webots and ROS joint simulation (I): software installation
Drawing with MATLAB (1)
关于极客时间 | MySQL实战45讲的部分总结
Matlab function foundation (directly abandon version)
Summary of common instructions for arm assembly