1:代碼如下:

// 3.5.cpp : 定義控制台應用程序的入口點。 // #include "stdafx.h" #include <iostream> using namespace std; void main() { int iYear; cout << "請輸入年份" << endl; cin >> iYear; if(iYear%4==0) { if(iYear%100==0) { if(iYear%400==0) cout << "" << endl; else cout << "" << endl; } else cout << "這是個閏年" << endl; } else cout << "這不是個閏年" << endl; } /*判斷閏年的方法是看該年份是否能被4整除、不能被100整除但能被400整除*/
運行結果: