close

//---------------------------------------------------------------------------
/****************************************************************************
練習6-4:閏年的定義為可被4整除而不可被100整除的年份,或者能被400整除的年份。*
         請寫一個程式,來判斷某一年是否為閏年。                           *
****************************************************************************/
#include <iostream>
#include <string>
//---------------------------------------------------------------------------
int year;


int main(int argc, char* argv[])
{
        std::cout << "Enter year,system will tell you whether it is bissextile "
                  << "or not: \n";

        std::cin >> year;
        if (year%4000==0)
        {
          std::cout << year << " is not bissextile\n";
          std::system("pause");
          return 0;
        }
        else if (year%400==0)
        {
          std::cout << year << " is bissextile\n";
          std::system("pause");
          return 0;
        }
        else if (year%4==0 && year%100!=0)
            std::cout << year << " is bissextile\n";
        else
            std::cout << year << " is not bissextile\n";

        std::system("pause");
        return 0;
}
//---------------------------------------------------------------------------


題目來源:C++風格與藝術 第二版 Steve Oualline 著 黃吉霈 編譯
答案來源:自我撰寫(不保證正確喔)

arrow
arrow
    全站熱搜

    jumbowind 發表在 痞客邦 留言(0) 人氣()