2017年10月7日 星期六

[C_MM35-易] 平、閏年判定(C++)

[C_MM35-易] 平、閏年判定

問題描述:試撰寫一個程式,可由鍵盤讀入一個 4 位數的整數,代表西洋的年份,然後判別這個年份是否為閏年(每四年一閏,每百年不閏,每四百年一閏,例如西元 1900 雖為 4 的倍數,但可被 100 整除,所以不是閏年,同理, 2000 年是閏年,因可被 400 整數,而 2004 當然也是閏年,因可以被 4 整除)。
輸入說明輸入西元年份。
輸出說明:輸出閏年(Bissextile Year)或平年(Common YearCommon Year)。範例:

Sample Input:Sample Output:
2000
2003
Bissextile Year
Common Year


  1. #include <iostream>  
  2. using namespace std;  
  3.   
  4. int main() {  
  5.     //[C_MM35-易] 平、閏年判定  
  6.     int year;  
  7.     while(cin >> year)  
  8.     {  
  9.         if(year%4==0)  
  10.         {  
  11.             if(year % 100 != 0 || year % 400 == 0)  
  12.             {  
  13.                 cout << "Bissextile Year" << endl;  
  14.             }  
  15.             else  
  16.             {  
  17.                 cout << "Common Year" << endl;  
  18.             }  
  19.         }  
  20.         else  
  21.         {  
  22.             cout << "Common Year" << endl;  
  23.         }  
  24.     }  
  25.     return 0;  

沒有留言:

張貼留言