问答题

函数fun的功能是:根据所给的年、月、日,计算出该日是这一年的第几天,并作为函数值返回。其中函数isleap用来判别某一年是否为闰年。 例如,若输入:2008 5 1,则程序输出:2008年5月1日是该年的第122天。 请在程序的下划线处填入正确的内容,并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构!1 #include<stdio.h>2 int isleap(int year)3 {int leap;4 leap=(year%4==0 &&year%100 !=0|| year%400==0);5 /**********found**********/6 return__(1)__;7 }8 int fun(int year,int month,int day) {int {table[13]={0,31,28,31,30,31,9 30,31,31,30,31,30,31};10 int days=0,i;11 for(i=1;i<month;i++)12 days=days+table[i];13 /**********found**********/14 days=days+__(2)__;15 if(isleap(year)&&month>2)16 /**********found**********/17 days=days+__(3)__;18 return days;19 }20 main()21 { int year,month,day,days;22 printf(’’请输入年、月、日:’’);23 scanf(’’%d%d%d’’,&year,&month,& day);24 days =fun(year,month,day);25 printf(’’%d年%d月%d日是该年的第%d天\n’’,year,month,day,days);26 }

【参考答案】

正确答案:(1)leap (2)day (3)1
热门 试题

问答题
给定程序MODI1.C中函数fun的功能是:对N名学生的学习成绩,按从高到低的顺序找出前m(m≤10)名学生来,并将这些学生数据存放在一个动态分配的连续存储区中,此存储区的首地址作为函数值返回。 请改正函数fun中指定部位的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!1 #include<stdio.h>2 #include<stdlib.h>3 #include<string.h>4 #define N 105 typedef struct ss6 { char num[10];7 int s;8 } STU;9 STU *fun(STU a[],int m)10 {STU b[N],*t;11 int i,j,k;12 /**********found**********/13 t=(STU *)calloc(sizeof(STU),m)14 for(i=0;i<N;i++)b[i]=a[i];15 for(k=0;k<m;k++)16 { for(i=j=0;i<N;i++)17 if(b[i].s>b[j].s) j=i ;18 /**********found**********/19 t(k)=b(j);20 b[j].s=0;21 }22 return t;23 }24 outresult(STU a[],FILE *pf)25 { int i;26 for(i=0;i<N;i++)27 fprintf(pf,’’No=%s Mark=%d\n’’,a[i].num,a[i].s);28 fprintf(pf,’’\n\n’’);29 }30 main()31 { STU a[N]={{’’A01’’,81},{’’A02’’,89},{’’A03’’,66},{’’A04’’,87},{’’A05’’,77},{’’A06’’,90},{’’A07’’,79},{’’A08’’,61},{’’A09’’,80},{’’A10’’,71}};32 STU *pOrder;33 int i,m;34 printf(’’*****The Original data*****\n’’);35 outresult(a,stdout);36 printf(’’\nGive the number of the students who have better score:’’);37 scanf(’’%d’’,&m);38 while(m>10)39 { printf(’’\nGive the number of the students who have better score:’’);40 scanf(’’%d’’,&m);41 }42 porder=fun(a,m);43 printf(’’***** THE RESULT ***** \n’’);44 printf(’’The top:\n’’);45 for(i=0;i<m;i++)46 printf(’’%s%d\n’’,pOrder[i].num,pOrder[i].s);47 free(pOrder);48 }