#include
int main(void)
{
unsigned int year=0;
printf("input a year!");
scanf("%d", &year); if(year % 400==0 || ((year % 100 != 0) && (year % 4 ==0)))
{
printf("是闰年"); }
else
{ printf("不是闰年");
} return 0;
}
#include
using namespace std;
int main()
{int year, leap;
cout<<"please enter a year:";
cin>>year;
if(year%4==0&&year%100!=0||year%400==0)
cout<<"year is a leap year"<
cout<<"year is not a leap year"<
}
这个相对来说更简洁一点、、、看得更加清楚点。
#include
using namespace std;
int main()
{
bool leapyear(int year);
int year;
bool leap;
cout<<"请输入年份:";
cin>>year;
getchar();
leap =leapyear(year);
if (leap)
cout<
cout <
return 0;
}bool leapyear(int year){
bool leap;
if (year%4==0)
{ if(year%100==0)
{ if(year%400==0)
leap=true;
else
leap=false;}
else
leap=true;
}
else
leap=false;return leap;}