判断某一年是否是闰年
#include <iostream>
using namespace std;
//判断某一年是否是闰年
//闰年的条件是:1.能被4整除而不能被100整除 2.同时能被100和400整除
int main()
{
cout << "请输入要判断的年份:" << endl;
int x = 0;
cin >> x;
if (x % 4 == 0 && x % 100 != 0)
{
cout <<x<< "年为闰年!" << endl;
}
else if (x % 100 == 0 && x % 400 == 0)
{
cout << x << "年为闰年!" << endl;
}
else
{
cout << x << "年不是闰年!" << endl;
}
system("pause");
return 0;
}
转载自:黑凤梨の博客