//判断是否为闰年,是该年的哪一天 #include <iostream> using namespace std; int sum(int month,int day); int leap(int year); int main() { int year,month,day; cout<<"请输入一个日期: "; cin>>year>>month>>day; int days=sum(month,day); if(leap(year)&&month>2) days++; cout<<year<<"年"<<month<<"月"<<day<<"日是这一年的第"<<days<<"天。\n"; if(year%4==0&&year%100!=0||year%400==0) cout<<"该年是闰年"; else cout<<"该年不是闰年"; } int sum(int month,int day) { int day_month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; for(int i=1;i<month;i++) day+=day_month[i]; return day; } int leap(int year) { int leap=year%4==0&&year%100!=0||year%400==0; return leap; }
时间: 2024-10-24 18:31:03