isleap.cpp

来自「C++&datastructure书籍源码,以前外教提供现在与大家共享」· C++ 代码 · 共 35 行

CPP
35
字号
#include <iostream>using namespace std;// illustrates user-defined function for determining leap yearsbool IsLeapYear(int year)// precondition: year > 0// postcondition: returns true if year is a leap year, else returns false {    if (year % 400 == 0)         // divisible by 400    {   return true;    }    else if (year % 100 == 0)    // divisible by 100    {   return false;    }    else if (year % 4 == 0)      // divisible by 4    {   return true;    }    return false;}int main(){    int year;    cout << "enter a year ";    cin >> year;    if (IsLeapYear(year))    {   cout << year << " has 366 days, it is a leap year" << endl;    }    else    {   cout << year << " has 365 days, it is NOT a leap year" << endl;    }    return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?