更多"改错题 【题目】 以下程序中,函数fun(int m, int fac"的相关试题:
[简答题]改错题
下列给定程序中,函数fun( )的功能是:读入一个字符串(长度<20),将该字符串中的所有字符按ASCII码降序排序后输出。
例如:输入dafhc,则应输出hfdca。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include
#include
/**********************found***********************/
int fun(char t[ ])
{
char c;
int i,j;
for(i=0;i
[填空题]#include
int f=1;
int fac(int n)
f=f*n;
return f;
main( )
int i;
for(i=1;i<=4,i++)
printf("%d!=%d/n",i,fac(i));
程序运行结果为: ______
[填空题]#include
int f=1;
int fac(int n)
{f=f*n;
return f;
}
main( )
{int i;
for(i=1;i<=4,i++)
{printf("%d!=%d/n",i,fac(i));}
}
程序运行结果为: ______
[简答题]改错题
下列给定程序中,函数fun( )的功能是计算并输出high以内的素数之和。high由主函数传给fun( )函数。若high的值为100,则函数的值为1060。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include
#include
#include
int fun(int high)
{
int sum=0,n=0, j, yes;
while(high>=2)
{
yes = 1;
for(j=2; j<=high/2; j++)
/**********************found***********************/
ifhigh%j==0
{
yes=0;
break;
}
/**********************found***********************/
if(yes==0)
{
sum+=high;
n++;
}
high--;
}
return sum;
}
main( )
{
clrscr( );
printf("%d/n",fun(100));
}
[简答题]改错题【程序功能】 函数fun的功能是将str所指向的一行包含若干单词的文本(单词之间用空格隔开)依次拆分成长度不超过20个字符的若干文本行,单词不跨行,且使拆分出的行数最少,再将拆分出的每行字符以字符串的形式存储到page指向的二维数组的一行中,函数返回拆分出的行数 【测试数据与运行结果】 测试数据:A great discovery solves a greate problem. 屏幕输出: A great disconvery solves a great problem【含有错误的源程序】以下源程序已保存在T盘myf1.c文件内,考生可直接打开该文件调试程序#include #include #include int fun(char str[],char pag[][]){int i,k=0,j,flag=1; while(*str && flag) {if(strlen(str)<20) {pag[k]=str; flag=0; } else {i=20; while(str[i]!=’ ’) i--; for(j=0;j
[简答题]改错题
下列给定程序中,函数fun( )的功能是根据整型形参m,计算如下公式的值。
y=1-1/(2×2)+1/(3×3)-1/(4×4)+…+(-1)(m+1)/(m×m)
例如:m中的值为5,则应输出0.838611。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include
#include
double fun(int m)
{ double y=1.0;
/**********************found***********************/
int j=1;
int i;
for(i=2; i<=m; i++)
{
j=-1*j;
/**********************found***********************/
y+=1/(i * i);
}
return(y);
}
main( )
{
int n=5;
clrscr( );
printf("/nThe result is %lf/n" ,fun(n));
}
[多项选择]改错题
下列给定程序中,函数fun( )的功能是:从n个学生的成绩中统计出高于平均分的学生人数,人数由函数值返回,平均分存放在形参aver所指的存储单元中。例如输入8名学生的成绩:
85 65.5 69 95.5 87 55 62.5 75
则高于平均分的学生人数为4(平均分为74.312500)。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include
#include
#define N 20
int fun(float *s, int n,float *aver)
{
/**********************found***********************/
int ave ,t=0;
int count=0,k,i;
for(k=0;k
[填空题]
[程序]
#include
void fa(int&a,int&b)
{int t=a;a=b;b=t;}
void fb(int a,int b)
{ int t=a;a=b;b=t;}
void main(void)
{int c[2]={100,200},d[2]={300,400};
fa(c[0],c[1]); cout<
rb(d[0],d[1]); cout<
}
程序输出的第一行是(),第二行是()。
[填空题]
[程序]
#include
int f(int a,int &b,int *c)
{
a+=b; b+=*c;*c+=a;
return (a+b+*c);
}
void main(void)
{
int x=5,y=5,z=6,sum;
for(int i=0;i<2;i++){
sum=f(x,y,&z);
cout<
}
}
执行程序后输出的第一行是___(1)___,第二行是___(2)___。
[单项选择]有以下程序:
int a=2;
int f(int n)
{static int a=3;
int t=0;
if(n%2){ static int a=4; t+=a++; } else { static int a=5; t+=a++; } return t+a++;
}
main( )
{ int s=a,i; for(i=0;i<3;i++) s+=f(i); printf("%d/n",s);
}
程序运行后的输出结果是______。
A. 26
B. 28
C. 29
D. 24
[单项选择]有以下程序:
int a=4;
int f(int n)
int t=0;static int a=5;
if(n%2) int a=6;t+=a++;
elseint a;7;t+=a++;
return t+a++;
main( )
int s=a,i=0;
for(;i<2;i++)s+=f(i);
printf("%d/n",s);
程序运行后的输出结果是()。
A. 24
B. 28
C. 32
D. 36
[单项选择]
有以下程序:
int a=2;
int f(int n)
{static int a=3;
int t=0;
if(n%2){static int a=4;t+=a++;
}
else
{
static int a=5; t+=a++;
}
return t+a++;
}
main( )
{ int s=a,i;
for(i=0;i<3;i++) s+=f(i);
printf("%d/n",s);
}
程序运行后的输出结果是()。
A. 26
B. 28
C. 29
D. 24
[单项选择]有以下程序:
int fun(int x[],int n)
static int sum=0,i;
for(i=0;i<n;i++)sum+=x[i];
return sum;
main( )
int a[]=1,2,3,4,5,b[]=6,7,8,9,s=0;
s=fun(a,5)+fun(b,4);printf("%d/n",s);
程序执行后的输出结果是( )。
A. 45
B. 50
C. 60
D. 55
[单项选择]有以下程序:
int fa(int x)
return x*x;
int fb(int x)
return x*x*x;
int f(int (*f1)( ),int (* f2)( ),int x)
return (*f2)(x)-(*f1)(x);
main( )
int i;
i=f(fa,fb,2);
printf("%d/n",i);
程序运行后的输出结果是 ( )
A. -4
B. 1
C. 4
D. 8