题目
请补充函数fun(),函数fun()的功能是求7的阶乘。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio.h>
long fun(int n)
{
if(【 】)
return(n*fun(【 】);
else if(【 】)
return 1;
}
main()
{
int k=7;
printf("%d!=%ld\n", k, fun(k));
}
第1题
str是一个由数字和字母字符组成的字符串,由变量hum传入字符串长度。请补充函数fun(),该函数的功能是:把字符串str中的数字字符转换成数字并存放到整型数组bb中,函数返回数组bb的长度。
例如:str=“Bcdl23e456hui890”,结果为:123456890。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio.h>
define N 80
int bb[N];
int fun(char s[ ],int bb[ ],int num)
{
int i,n=0;
for(i=0;i<num;i++)
{
if(【 】)
{
bb[n]=【 】;
n++;
}
}
return【 】;
}
main()
{
char str[N];
int num=0,n,i;
printf("Enter a string:\n");
gets(str);
while(str[num])
num++;
n=fun(str,bb,num);
printf("\nbb=");
for(i=0;i<n;i++)
printf("%d",bb[i]);
}
第2题
函数fun的功能是将一个数字字符串转换为一个整数,请将函数补充完整。
int fun(char*str){
int hum=0;
while(*str){
num*=10;
num+=______
str++;
}
return num;
}
第3题
第4题
有如下递归函数:
int Fun(int n){
if(n<=1) return 1;
______
}
请补充完整,使得函数Fun能够正确计算形参n的阶乘。
第5题
请将下列类定义补充完整。
class Base{public:void fun(){cout<<"Base::fun"<<end;}};
class Derived:public Base
{
public:
void fun()
{
【 】//显式调用基类的fun函数
cout<<"Derived::fun"<<endl;
}
};
第6题
请补充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);
}
第7题
请将下列类定义补充完整。
class Base{public:void fun(){cout<<"Base∷fun"<<end1;}};
c1ass DehVed:public Base
{
public:
void fun(){
______ ∥显式调用基类的fun函数
cout<<"Derived∷fun"<<endl;
}
};
第8题
请将下列类定义补充完整。
class Base{public:void fun(){cout<<"Base::fun"<<endl;}};
class Derived:public Base
{
public:
void fun(){
______//显式调用基类的fun函数
cout<<"Derived::fun"<<endl;
}
};
第9题
●试题四
请补充函数fun(),该函数的功能是将字符串tt中的大写字母都改为对应的小写字母,其他字符不变。例如,若输入"Are you come from Sichuan?",则输入"are you come from sichuan?"。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#include<string.h>
#include<conio.h>
char *fun(char tt[])
{
int i;
for(i=0;tt[i];i++)
{
if((tt[i]>=′A′)&&((1) ))
(2) ;
}
return ((3) ) ;
}
main()
{
char tt[81];
printf("\nPlease enter a string:");
gets(tt);
printf("\nThe result string is: \n%s",
fun(tt));
}
第10题
请将下列类定义补充完整。
class Base{public:void fun(){tout<<"Base::fun"<<endl;}};
class Derived:public Base
{
public:
void fun()
{
______//显示调用基类的fun函数
cout<<"Derived::fun"<<endl;
};
为了保护您的账号安全,请在“赏学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!