1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
| #include<stdio.h> #include<stdlib.h> struct date_rec { int day ; int month ; int year ; } ;
void input_date(struct date_rec *current_date); void increment_date(struct date_rec *current_date); void output_date(struct date_rec *current_date);
int main() { struct date_rec *today=malloc(50*sizeof(int)); input_date(today); increment_date(today); output_date(today); free(today); return 0; }
void input_date(struct date_rec *current_date) { printf("请输入当前日期(年 月 日):"); scanf("%d %d %d",¤t_date->year,¤t_date->month,¤t_date->day); }
void increment_date(struct date_rec *current_date) { if(current_date->month==2) { if(current_date->year%4==0&¤t_date->year%100!=0||current_date->year%400==0) { if(current_date->day==29) { current_date->day=1; current_date->month+=1; } else current_date->day+=1; } else { if(current_date->day==28) { current_date->day=1; current_date->month+=1; } else current_date->day+=1; } } else if(current_date->month==1||current_date->month==3||current_date->month==5||current_date->month==7||current_date->month==8||current_date->month==10) { if(current_date->day==31) { current_date->day=1; current_date->month+=1; } else current_date->day+=1; } else if(current_date->month==12) { if(current_date->day==31) { current_date->day=1; current_date->month=1; current_date->year+=1; } else current_date->day+=1; } else { if(current_date->day==30) { current_date->day=1; current_date->month+=1; } else current_date->day+=1; } }
void output_date(struct date_rec *current_date) { printf("当前日期:%d年%d月%d日!",current_date->year,current_date->month,current_date->day); }
|