当前位置:网站首页>编程训练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;
边栏推荐
- Summary of mobile terminal lightweight model data
- Segmentation of structured light images using segmentation network
- What is Qi certification Qi certification process
- Implementation of ffmpeg audio and video player
- Software engineering - personal assignment - question review and personal summary
- Batch execute SQL file
- Leetcode notes: binary search simple advanced
- QT_ AI
- 51 MCU project design: Based on 51 MCU clock perpetual calendar
- RecyclerView Item 根据 x,y 坐标得到当前position(位置)
猜你喜欢

Exploration of webots and ROS joint simulation (I): software installation

51 single chip microcomputer project design: schematic diagram of timed pet feeding system (LCD 1602, timed alarm clock, key timing) Protues, KEIL, DXP

Whale conference provides digital upgrade scheme for the event site

What is Qi certification Qi certification process

51 MCU project design: Based on 51 MCU clock perpetual calendar

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

三菱PLC若想实现以太网无线通讯,需要具备哪些条件?

滑块验证 - 亲测 (京东)

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

Selenium builds cookies pool to bypass authentication and anti crawl login
随机推荐
Whale conference provides digital upgrade scheme for the event site
Compiling owncloud client on win10
Leetcode22 summary of types of questions brushing in 2002 (XII) and collection search
Using transformers of hugging face to realize multi label text classification
2020-10-20
(5) Matrix key
Using transformers of hugging face to realize text classification
Recovering the system with Clonezilla USB disk
1.25 suggestions and design of machine learning
The best time to buy and sell stocks to get the maximum return
51 single chip microcomputer project design: schematic diagram of timed pet feeding system (LCD 1602, timed alarm clock, key timing) Protues, KEIL, DXP
Backward usage
Use of PCL
Leetcode notes: binary search simple advanced
Using transformers of hugging face to realize named entity recognition
Clion installation + MinGW configuration + opencv installation
STM32 project design: temperature, humidity and air quality alarm, sharing source code and PCB
MPC learning notes (I): push MPC formula manually
The principle and function of focus
opencv學習筆記三