1.while(n!=0)等价于while(n)
2数组求天数差
#include <stdio.h>
int monthday[] = { 0, // (1)
31, 28, 31, 30, 31, 30,
31, 31, 30, 31, 30, 31
};
int sumday[13];
char str[100];
int y, m, d;
int main() {
int i;
while (scanf("%s", str) != EOF) {
sscanf(str, "%4d/%2d/%2d", &y, &m, &d);
if (y % 4 == 0 && y % 100 || y % 400 == 0) {
monthday[2] = 29; // (2)
}
else {
monthday[2] = 28;
}
sumday[0] = 0;
for (i = 1; i <= 12; ++i) { // (3)
sumday[i] = sumday[i - 1] + monthday[i];
}
int ans = sumday[m - 1] + d; // (4)
printf("%d\n", ans);
}
return 0;
}
3.最大公约最小公倍数