[GESP202303]每月天数
2026-08-21 15:45:09
发布于:上海
3阅读
0回复
0点赞
由于当此年是闰年时,那么2月就是29天
其余的小月(4、6、9、11)为30天
大月(1、3、5、7、8、10、12)为31天
#include<iostream>
using namespace std;
bool year(int year_s){
if(year_s%100==0){
if(year_s%400==0){
return true;
}
else{
return false;
}
}
else{
if(year_s%4==0){
return true;
}
else{
return false;
}
}
}
int main(){
int year_s,month;
cin>>year_s>>month;
if(month==2){
if(year(year_s)){
cout<<29;
}
else{
cout<<28;
}
}
else{
if(month==7||month==8){
cout<<31;
}
else if(month<7){
if(month%2==1){
cout<<31;
}
else{
cout<<30;
}
}
else if(month>8){
if(month%2==1){
cout<<30;
}
else{
cout<<31;
}
}
}
}
这里空空如也







有帮助,赞一个