填空题
请补充fun函数,该函数的功能是:判断一个年份是否为闰年。
例如,1900年不是闰年,2004是闰年。
[注意] 部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
[试题源程序]
#include<stdio.h>
#include<conio.h>
int fun(int n)
int fiag=0;
if(n%4==0)
if(
(1)
)
fiag=1;
if(
(2)
)flag=1;
return
(3)
;
void main()
int year;
clrscr();
printf("Input the year:");
scanf("%d", &year);
if(fun(year))
printf("%d is a leap year.\n", year);
else
printf("%d is not a leap year.\n", year);
【参考答案】
[1] n%100 !=0
[2] n%400==0
[3] flag
点击查看答案&解析
<上一题
目录
下一题>
热门
试题
问答题
学生的记录由学号和成绩组成,N名学生的数据已存放在主函数的结构体数组s中,请编写函数fun,它的功能是:把低于平均分的学生数据放在b所指的数组中,低于平均分的学生人数通过形参n传回,平均分通过函数值返回。 [注意] 部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在fun函数的花括号中填入所编写的若干语句。 [试题源程序] #include<stdio.h> #define N 8 typedef struct char num[10]; double s; STREC; double fun(STREC *a, STREC *b, int *n) void main() STREC s[N]= GA05 , 85, GA03 , 76, GA02 , 69, GA04 , 85, GA01 , 91, GA07 , 72, GA08 , 64, GA06 , 87; STREC h[N], t; FILE *out; int i, j, n; double ave; ave=fun(s, h, &n); printf( The %d student data which is lower than %7.3 f: n , n, ave); for(i=0; i<n; i++) printf( %s %4.1f n , h[i]. num, h[i].s); printf( n ); out=fopen( out.dat , W ); fprintf(out, %d n%7.3f n , n, ave); for(i=0; 2<n-1; i++) for(j=i+1; j<n; j++) if(h[i]. s>h[j].s) t=h[i]; h[i]=h[j]; h[j]=t; for(i=0; 2<n; i++) fprintf(out, %4.1f n , h[i].s); fclose(out);
点击查看答案&解析
问答题
下列给定程序中,函数fun()的功能是:将s所指字符串中的字母转换为按字母序列后续字母(但Z转换为A,z转换为a),其他字符不变。 请改正程序指定部位的错误,使它能得到正确结果。 [注意] 不要改动main函数,不得增行或删行,也不得更改程序的结构。 [试题源程序] #include<stdio.h> #include<ctype.h> void fun(char *s) **********found********** while(*s!=’@’) if(*s>=’A’ && *s<=’Z’ || *s>=’a’ && ’s<=’z’) if(*s==’Z’) *s=’A’; else if(*s==’z’) *s=’a’; else *s+=1; **********found********** (*s)++; void main() char s[80]; printf( n Enter a string with length<80. : n n ); gets(s); printf( n The string: n n t ); puts(s); fun(s); printf ( n n The Cords: n n ); puts(s);
点击查看答案&解析
相关试题
学生的记录由学号和成绩组成,N名学生的数...
下列给定程序中,函数fun()的功能是:将s...