2、判断是否为闰年

 1 #include<iostream>
 2 
 3 using namespace std;
 4 
 5 int main(void)
 6 {
 7     // 输入任意一个年份判断其是否为闰年
 8     int iYear = 0;
 9     cout << "请输入年份" << endl;
10     cin >> iYear;
11 
12     // 判断闰年的条件,能被4整出且不能被100整除,或者能被400整除
13     if (iYear % 4 == 0 && iYear % 100 != 0 || iYear % 400 == 0)
14     {
15         cout << iYear << "是闰年" << endl;
16     }
17     else
18     {
19         cout << iYear << "不是闰年" << endl;
20     }
21     return 0;
22 }

猜你喜欢

转载自www.cnblogs.com/tito/p/12372840.html