当前位置:网站首页>编程训练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;
边栏推荐
- VS2005 project call free() compiled with static libcurl library reported heap error
- Google Chrome collection
- Solution to the encoding problem encountered by the crawler when requesting get/post
- Use of PCL
- isinstance()函数用法
- Embedded Software Engineer (6-15k) written examination interview experience sharing (fresh graduates)
- Detailed process of generating URDF file from SW model
- STM32 project design: smart door lock PCB and source code based on stm32f1 (4 unlocking methods)
- 1.21 study logistic regression and regularization
- Leetcode: array fast and slow pointer method
猜你喜欢

Fourier transform of image

Opencv learning notes II

Isinstance() function usage

Object extraction_ nanyangjx
![[unity mirror] use of networkteam](/img/b8/93f55d11ea4ce2c86df01a9b03b7e7.png)
[unity mirror] use of networkteam

STM32 project design: an e-reader making tutorial based on stm32f4

Degree of freedom analysis_ nanyangjx

How to realize wireless Ethernet high-speed communication for multiple Mitsubishi PLCs?

Digital image processing learning (II): Gaussian low pass filter

2020-10-20
随机推荐
isinstance()函数用法
Relationship extraction -- casrel
Opencv learning notes 3
Reverse crawling verification code identification login (OCR character recognition)
How to correctly PIP install pyscipopt
keras_ Callback function summary
What is Qi certification Qi certification process
Whale conference provides digital upgrade scheme for the event site
Line detection_ nanyangjx
Exploration of webots and ROS joint simulation (I): software installation
Analysis of Yolo series principle
OpenCV Learning notes iii
XSS 跨站脚本攻击
Using transformers of hugging face to realize text classification
Principle of playing card image segmentation
鲸会务一站式智能会议系统帮助主办方实现数字化会议管理
关于极客时间 | MySQL实战45讲的部分总结
Solution to the encoding problem encountered by the crawler when requesting get/post
Apple motherboard decoding chip, lightning Apple motherboard decoding I.C
Polka lines code recurrence