c++,编写一个程序,判断某一年是否为闰年。

2024-12-16 15:36:50
推荐回答(3个)
回答1:

#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;
}

回答2:

#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"< else
cout<<"year is not a leap year"< return 0;
}
这个相对来说更简洁一点、、、看得更加清楚点。

回答3:

#include
using namespace std;
int main()
{
bool leapyear(int year);
int year;
bool leap;
cout<<"请输入年份:";
cin>>year;
getchar();
leap =leapyear(year);
if (leap)
cout<else
cout <cout<<"a leap year"<getchar();
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;}