计算某年月份天数
代码:#include <iostream>
using namespace std;
int main() {
int y, m, r;
bool a;
cin >> y >> m;
a = ((!(y % 4) && (y % 100))) || !(y % 400);
switch (m) {
case 1: r = 31; break;
case 2: r = a ? 29 : 28; break;
case 3: r = 31; break;
case 4: r = 30; break;
case 5: r = 31; break;
case 6: r = 30; break;
case 7: r = 31; break;
case 8: r = 31; break;
case 9: r = 30; break;
case 10: r = 31; break;
case 11: r = 30; break;
case 12: r = 31; break;
default: r = 0; break;
}
cout << r;
return 0;
}
运行结果:
2000 2
29
页:
[1]