-
闰年的条件是符合下面二者之一: ①能被4整除,但不能被100整除,如2008 ②能被400整除,如2000
方式一
#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;
}
方式二
#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";
}