- /*5_2.輸入西元年數,判斷其是否為閏年*/
- #include<iostream>
- using namespace std;
- int main()
- { int year , year_1 , year_2 , a ;
- cout << "請輸入民國年或西元年(民國後打1/西元後打2):" << endl;
- cin >> a;
-
- if(a==1){
- cout << "Please enter a year(民國年):" << endl;
- cin >> year_1;
-
- year=year_1+1911;
- if((year%4==0) && (year%100!=0))
- {
- cout << "西元" << year << "年是閏年" << endl;
- }
-
- else if((year%400==0) && (year%100==0))
- {
- cout << "西元" << year << "年是閏年" << endl;
- }
- else
- {cout << "西元" << year << "年不是閏年" << endl; }
-
- }
-
- if(a==2){
- cout << "Please enter a year(西元年):" << endl;
- cin >> year_2;
-
- year=year_2;
- if((year%4==0) && (year%100!=0))
- {
- cout << "西元" << year << "年是閏年" << endl;
- }
- else if((year%400==0) && (year%100==0))
- {
- cout << "西元" << year << "年是閏年" << endl;
- }
- else
- {cout << "西元" << year << "年不是閏年" << endl; }
-
- }
-
- system("pause");
- return 0;
-
-
- }
複製代碼 |