3144 - 例题2-3 判断闰年
输入一个2000至2500年间(包含2000年和2500年)的任意年份,判断是否是闰年。
Input
输入一个整数year,表示年份。输入保证2000≤year≤2500。
Output
如果输入的年份是闰年,请输出“leap year”,否则请输出“not leap year”。
请注意不需要输出引号,行尾输出换行。
Examples
Input
2000
Output
leap year
Solution C
#include <stdio.h> int main() { int year, a, b, c; scanf("%d", &year); a = year % 4; if(a == 0) { b = year % 100; if(b == 0) { c = year % 400; if(c == 0) printf("leap year\n"); else printf("not leap year\n"); } else printf("leap year\n"); } else printf("not leap year\n"); return 0; system("pause"); }
Solution C++
#include <iostream> using namespace std; int main() { int a; cin>>a; if(a%100==0) { if(a%400==0) cout<<"leap year"<<endl; else cout<<"not leap year"<<endl; } else { if(a%4==0) cout<<"leap year"<<endl; else cout<<"not leap year"<<endl; } return 0; }