闰年计算

来源:互联网 发布:mac日历添加美国节日 编辑:程序博客网 时间:2024/05/02 01:39

闰年是指能被400整除!或者(能被4整除但不能被100整除)的年份!

代码如下:

#include<iostream>using namespace std;int leapyear(int year){if ((year%400 == 0)||(year%100 != 0&&year%4 == 0))return 1;return 0;}int main(){cout<<"Please print leap year from 2000 to 3000 !"<<endl;for (int i = 2000; i <= 3000; i++ ){if (leapyear(i))cout<<i<<" ";}cout<<endl;system("pause");return 0;}


0 0
原创粉丝点击