- うるう年の条件は次のいずれかです。①4で割り切れるが、2008年のように100で割り切れない②2000
モード1のように400で割り切れる
#include <iostream>
using namespace std;
int main()
{
int a;
cout<<"请输入年份"<<endl;
cin>>a;
if(a%4==0&&a%100!=0||a%400==0)
cout<<"闰年"<<endl;
else
cout<<"不是闰年"<<endl;
}
方法2
#include <iostream>
using namespace std;
int main()
{
int y;
cin>>y;
if(y%4==0)
{
if(y%100==0)
{
if(y%400==0)
cout<<"IsLeapYear";
else
cout<<"NotLeapYear";
}
else cout<<"IsLeapYear";
}
else cout<<"NotLeapYear";
}