- The conditions for a leap year are one of the following: ① Divisible by 4, but not divisible by 100, such as 2008 ② Divisible by 400, such as 2000
mode one
#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;
}
Way two
#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";
}