当前位置:网站首页>Calculation days ()

Calculation days ()

2022-06-22 08:10:00 Study hard 867

This problem requires writing a program to calculate the day of a certain month in a certain year .

Input format :

The input is formatted in one line “yyyy/mm/dd”( namely “ year / month / Japan ”) Give the date . Be careful : The criterion of leap year is that the year can be 4 Divide but not be 100 to be divisible by 、 Or can be 400 to be divisible by . Leap year's 2 Monthly 29 God .

Output format :

In one line, the output date is the day of the year .

sample input 1:

2009/03/02

sample output 1:

61

sample input 2:

2000/03/02

sample output 2:

62

Code : 

#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);
}

原网站

版权声明
本文为[Study hard 867]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206220802076420.html