c上机题目10套
- 格式:doc
- 大小:89.00 KB
- 文档页数:26
一、程序填空题
考试做题要求:
1、在__1__处填写正确的答案,并将下划线和数字删除。
2、将题目做完之后一定要保存。
3、不能删除/**********found**********/,也不能多行或少行。
1、请补充fun函数,fun函数的功能是求m的阶乘。
请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。
注意:部分源程序给出如下。
# include <>
long fun(int m)
{
if(___1___)
return (m*fun(___2___));
return ___3___;
}
main()
{
printf("8!=%ld\n",fun(8));
}
2、请补充fun函数,该函数的功能是:判断一个年份是否为闰年。
例如,2007年不是闰年,2008是闰年。
请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。
注意:部分源程序给出如下。
# include <>
# include <>
int fun(int n)
{
int flag=0;
if(n%4==0)
if(____1_____)
flag=1;
if(____2____) flag=1;
return ___3____;
}
main()
{
int year;
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);
}
3、函数fun的功能是:从三个形参x、y、z中找出中间的那个数,作为函数值返回。
例如,当x=121,y=456,z=333时,中间的数为333。
请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。
注意:部分源程序给出如下。
# include <>
int fun(int a,int b,int c)
{
int temp;
temp=(a>b) (b>c b : (a>c c : ___1___)) :
((a>c) ___2___ :
((b>c) c : ___3___));
return temp;
}
main()
{
int x=121,y=456,z=333,mid;
mid=fun(x,y,z);
printf("\nThe middle number is : %d\n",mid);
}
4、请补充函数fun(char *t),该函数的功能是把字符串中的内容逆置。
例如,字符串中原有的字符串为ABCDE,则调用该函数后,串中的内容为EDCBA。
请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。
注意:部分源程序给出如下。
# include <>
# include <>
# include <>
# define M 60
void fun(char *t)
{
int j,m=strlen(t)-1;
char s;
for(j=0;j
{
s=t[j];
___2___;
___3___;
}
}
main()
{
char b[M];
printf("Input a string:");
gets(b);
printf("The original string is:");
puts(b);
fun(b);
printf("\n");
printf("The reversal string :");
puts(b);
}
5、请补充main函数,该函数的功能是:从键盘输入一个长整数,如果这个数是负数,则取它的绝对值,并显示出来。例如,输入:-666,结果为:666。 仅在横线上填写所需的若干表达式或语句,请勿改动函数中的其他任何内容。
注意:部分源程序给出如下。
# include <>
# include <>
main()
{
long int a;
printf("Enter the data:\n");
scanf(___1___);
printf("The origial data is %ld\n",a);
if(a<0)
___2___;
printf("\n");
printf(___3___);
}
6、请补充函数fun,它的功能是:计算并输出m(包括m)以内能被2或5整除的所有自然数的倒数之和。
例如,在主函数中从键盘给m输入21后,输出为:s=。
请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。
注意:部分源程序给出如下。
# include <>
double fun(int m)
{
int j;
double toal=;
for(j=1;___1___;j++)
if(j%2==0 ___2___ j%5==0)
toal+=___3___/j;
return toal;
}
main()
{
int m;
double f; printf("\nInput m: ");
scanf("%d",&m);
f=fun(m);
printf("\n\ns=%f\n",f);
}
7、请补充fun函数,该函数的功能是把从键盘输入的3个整数按从大到小输出。
例如,输入11 65 13,结果输出65 13 11。
仅在横线上填写所需的若干表达式或语句,请勿改动函数中的其他任何内容。
注意:部分源程序给出如下。
# include <>
# include <>
main()
{
int a,b,c,t;
printf("Input a,b,c\n");
scanf("%d%d%d",&a,&b,&c);
if(___1___)
{
t=a;
a=b;
b=t;
}
if(___2___)
{
t=c;
c=a;
a=t;
}
if(___3___)
{
t=b;
b=c;
c=t; }
printf("The result\n");
printf("from big to small: %d %d %d\n",a,b,c);
}
8、给定程序的功能是分别统计字符串中大写字母和小写字母的个数。
例如,给字符串str输入:sfd34ddfoFFDEsd23sdf,则输出结果应为:cap=4,min=13
请勿改动函数中的其他内容,仅在横线上填写所需的若干表达式或语句。
注意:部分源程序给出如下。
# include <>
void fun(char *str,int *x,int *y)
{
while(*str)
{
if(*str>='A' && *str<='Z')
___1___;
if(*str>='a' && *str<='z')
___2___;
str++;
}
}
main()
{
char str[100];
int cap=0,min=0;
printf("\nPlease a string to count : ");
gets(str);
fun(str,&cap,&min);
printf("\n cap=%d min=%d\n",___3___);
}
9、给定程序的功能是求1/4的圆周长,函数通过形参得到圆的直径,函数返回1/4的圆周长(圆周长公式为:L=πd,在程序中定义的变量名要与公式的变量相同)。 例如,输入圆的直径值:,输出为:。
请勿改动主函数main与其他函数中的任何内容,仅在横线上填写所需的若干表达式或语句。
注意:部分源程序给出如下。
# include <>
double fun(double d)
{
return *___1___/;
}
main()
{
double z;
printf("Input the d of the round : ");
scanf("%lf",&___2___);
printf(" L=%lf\n ",fun(___3___));
}
10、函数fun的功能是:统计长整数test的各位上出现数字5、6、7的次数,并通过外部(全局)变量sum5、sum6、sum7返回主函数。
例如,当test=时,结果应该为:sum5=0 sum6=2 sum7=1。
请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。
注意:部分源程序给出如下。
# include <>
int sum5,sum6,sum7;
void fun(long test)
{
sum5=sum6=sum7=0;
while(test)
{
switch(___1___)
{
case 5:
sum5++;
___2___;
case 6: