#include<stdio.h> struct date{ int day; int month; int year; }; struct date *Time(struct date *Time){ scanf("%d %d %d", &Time->day, &Time->month, &Time->year); return Time; }; void print(int n); bool Isleap(int d); int caltime(struct date *dd); int main(){ struct date ti = { 0, 0, 0 }; printf("input the date(day month year)\n"); Time(&ti); print(caltime(&ti)); } bool Isleap(int d){ int answer; if ((d % 4 == 0 && d % 100 != 0) || d % 400 == 0){ answer = 1; } else{ answer = 0; } return answer; } int caltime(struct date *dd){ const int mnth[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; int yer = dd->year; int cnt = dd->day; int i; int midx = dd->month; for (i = 0; i < midx - 1; i++){ cnt += mnth[i]; } if (Isleap(yer)){ cnt++; } return cnt; } void print(int n){ printf("The time is %d\n", n); }
输入年月日,计算该年第几天
猜你喜欢
转载自blog.csdn.net/jzjz73/article/details/78007046
今日推荐
周排行