閏年的判斷

問題:公元年哪時候二月會閏月?

做法:判斷y是否被400整除,可以被4整除不被100整除。

程式範例解答

#include <iostream>
using namespace std;
void main(){
  int year;
  cout<<"請輸入年份"
  cin>>year;
  if(year%=400==0)||(year%4==0&&year%100!=0){
    cout<< "西元" << year << "年是閏年" << endl;
  }
  else{
    cout<< "西元" << year << "年是閏年" << endl;
  } 
  system("pause");
}

results matching ""

    No results matching ""