标签:int 分析 turn oid day style put stdio.h clu
《c语言程序设计》(第三版)何钦铭 P190
1 #include<stdio.h> 2 void month_day(int year,int yearday,int *pmonth,int *pday); 3 4 int main() { 5 int day,month,year,yearday; 6 printf("input year and yearday:"); 7 scanf("%d%d",&year,&yearday); 8 month_day(year,yearday,&month,&day); 9 printf("%d-%d-%d\n",year,month,day); 10 return 0; 11 } 12 13 void month_day(int year,int yearday,int *pmonth,int *pday) { 14 int k,leap; 15 int tab[2][13]= { 16 {0,31,28,31,30,31,30,31,31,30,31,30,31}, 17 {0,31,29,31,30,31,30,31,31,30,31,30,31}, 18 }; 19 leap = (year%4==0 && year%100!=0)||year%400==0; 20 for(k=1; yearday>tab[leap][k]; k++) 21 yearday-=tab[leap][k]; 22 *pmonth=k; 23 *pday=yearday; 24 }
分析:
1、用指针实现了两个返回值
2、二维数组+变量判断闰年
3、20-21非常巧妙
标签:int 分析 turn oid day style put stdio.h clu
原文地址:https://www.cnblogs.com/cxc1357/p/10759761.html