#include<iostream>
using namespace std;
int main()
{
int year;
cin >> year;
while (year>0)
{
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
{
cout << year << "年为闰年!" << endl;
}
else
{
cout << year << "年不是闰年!" << endl;
}
cin >> year;
}
system("pause");
return 0;
using namespace std;
int main()
{
int year;
cin >> year;
while (year>0)
{
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
{
cout << year << "年为闰年!" << endl;
}
else
{
cout << year << "年不是闰年!" << endl;
}
cin >> year;
}
system("pause");
return 0;
}
--------------------------------------------
#include<iostream>
using namespace std;
int main()
{
int year;
bool isleapyear;
cin >> year;
while (year>0)
{
isleapyear = ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0));
if (isleapyear)
{
cout << year << "年为闰年!" << endl;
}
else
{
cout << year << "年不是闰年!" << endl;
}
cin >> year;
}
system("pause");
return 0;
}
本文提供了一个使用C++编写的简单程序,用于判断输入的年份是否为闰年。程序通过循环接收用户输入,并利用布尔变量来简化条件判断。
651

被折叠的 条评论
为什么被折叠?



