当前位置:网站首页>计算天数()
计算天数()
2022-06-22 08:02:00 【好好学吧867】
本题要求编写程序计算某年某月某日是该年中的第几天。
输入格式:
输入在一行中按照格式“yyyy/mm/dd”(即“年/月/日”)给出日期。注意:闰年的判别条件是该年年份能被4整除但不能被100整除、或者能被400整除。闰年的2月有29天。
输出格式:
在一行输出日期是该年中的第几天。
输入样例1:
2009/03/02
输出样例1:
61
输入样例2:
2000/03/02
输出样例2:
62代码:
#include <stdio.h>
int main(){
int a[12]= {31,29,31,30,31,30,31,31,30,31,30,31};
int b[12]= {31,28,31,30,31,30,31,31,30,31,30,31};
int years,month,day,sum=0;
scanf("%d/%2d/%2d",&years,&month,&day);
int flag=0;
int i;
if((years%4==0&&years%100!=0)||years%400==0) {
flag=1;
}
if(flag==1) {
for(i=0; i<month-1; i++) {
sum=sum+a[i];
}
for(i=0; i<day; i++) {
sum=sum+1;
}
}
else {
for(i=0; i<month-1; i++) {
sum=sum+b[i];
}
for(i=0; i<day; i++) {
sum=sum+1;
}
}
printf("%d",sum);
}边栏推荐
- Use of keepalived high availability cluster
- Master data management system
- How can MySQL query the records with the largest consumption amount of each user?
- SVN 提交子文件夹问题
- QT 控件增加双击事件
- AudioQueue
- The jdbcurl is configured correctly in the project, but the jdbcurl is the wrong path after the project is started
- 计算水费问题
- lr 2022超详细安装教程「最新」
- Difference between ID instancetype nsobject *
猜你喜欢

模電實驗——實驗二 JFET共源極放大電路

【 Oracle database】 Nursery Mother Tutorial day13 date Function

An example shows the difference between let and VaR

Node red sends wechat official account message (template message)

MySQL view

Stored procedures and functions of MySQL

LR 2022 ultra detailed installation tutorial "latest"

mysql查询group by 1055 问题完美解决,最简单最便捷的方法

Detailed explanation of subnet mask

Relative positioning, absolute positioning, fixed positioning
随机推荐
Xlua environment configuration
Kubernetes practice
Master data management system
Charles uses
Use of keepalived high availability cluster
【Oracle 数据库】奶妈式教程 day11 数值函数
Example of using listagg in Oracle 11g (splicing the values of a field into a line, separated by commas)
A glimpse of easy rule
IP address planning
MySQL view
mysql截取字符串CS0000_1中_后面的字符
Mt4/mql4 getting started to mastering EA tutorial lesson 4 - common functions of MQL language (IV) - common functions of K-line value
What are uniapp, wap2app and 5 + app in dccloud?
Mt4/mql4 getting started to be proficient in EA tutorial lesson 6 - common functions of MQL language (VI) - common order function
ES6 set data type de duplication of array, intersection, union and difference
Windchill API drops
基于消息传递的并发编程(MPI)之异步收发
Idea reports an error "insufficient memory"
【 Oracle database】 Nursery Mother Tutorial day13 date Function
(9) Sequential queue and stack queue