日期

#include<stdio.h>
int main() {
int year, days, month = 0;
int ch[] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
printf("请输入年份,天数");
scanf("%d%d", &year, &days);
int t = (year % 4 == 0 && year % 100 != 0 || year % 400 == 0);
if (t == 1);
ch[1] = 29;
while (days > 0 && days <= 365 + t) {
days -= ch[month];
month++;
}
if (days <= 0) {
month -= 1;
days += ch[month];
}
printf("%d-%d-%d", year, month + 1, days);
return 0;
}

posted @ 2023-03-04 14:23  skj55  阅读(80)  评论(0)    收藏  举报