scanf("%f",s+i);
printf("\nThenumberofstudents:
%d\n",fun(s,m,&aver));
printf("Ave=%f\n",aver);
}
主要算法:
涉及知识点:
试题难度:
★★
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
10.下列给定程序中,函数fun的功能是:
将s所指字符串中出现的t1所指子串全部替换成t2所指子字符串,所形成的新串放在w所指的数组中。
在此处,要求t1和t2所指字符串的长度相同。
例如,当s指字符串中的内容为abcdabfab,t1指子串中的内容为ab,t2所指子串中的内容为99时,结果,在w所指的数组中的内容应为99cd99f99。
请改正程序中的错误,使它能得出正确的结果。
注意:
不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include
#include
#include
/********found********/
intfun(char*s,char*t1,char*t2,char*w)
{
inti;
char*p,*r,*a;
strcpy(w,s);
while(*w)
{
p=w;r=t1;
/********found********/
while(r)
if(*r==*p)
{
r++;p++;
}
else
break;
if(*r=='\0')
{
a=w;
r=t2;
while(*r)
{
*a=*r;
a++;
r++;}
w+=strlen(t2);
}
else
w++;
}
}
main()
{
chars[100],t1[100],t2[100],w[100];
clrscr();
printf("\nPleaseenterstrings:
");
scanf("%s",s);
printf("\nPleaseentersubstringt1:
");
scanf("%s",t1);
printf("\nPleaseentersubstringt2:
");
scanf("%s",t2);
if(strlen(t1)==strlen(t2)){
fun(s,t1,t2,w);
printf("\nTheresultis:
%s\n",w);
}
else
printf("Error:
strlen(t1)!
=strlen(t2)\n");
}
主要算法:
涉及知识点:
试题难度:
★★★★
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
11.下列给定程序中,函数fun的功能是:
将一个由八进制数字字符组成的字符串转换为与其面值相等的十进制整数。
规定输入的字符串最多只能包含5位8进制数字。
例如,若输入77777,则输出将是32767。
请改正程序中的错误,使它能得出正确结果。
注意:
不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include
intfun(char*p)
{
intn;
/********found********/
n=*p-'o';
p++;
/********found********/
while(*p!
=0)
{
n=n*7+*p-'o';
p++;
}
returnn;
}
main()
{
chars[6];
inti;
intn;
printf("Enterastring(0cataldigits):
");
gets(s);
if(strlen(s)>5)
{
printf("Error:
stringtoolonger!
\n\n");
exit(0);
}
for(i=0;s[i];i++)
if(s[i]<'0'||s[i]>'7')
{
printf("Error:
%cnotisocataldigits!
\n\n",s[i]);
exit(0);
}
printf("Theoriginalstring:
");
puts(s);
n=fun(s);
printf("\n%sisconveredtointegenumber:
%d\n\n",s,n);
}
主要算法:
涉及知识点:
试题难度:
★★
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
12.下列给定程序中函数fun的功能是:
求出在字符串中最后一次出现的子字符串的地
址,通过函数值返回,在主函数中输出从此地址开始的字符串;若未找到,则函数值为NULL。
例如,当字符串中的内容为abcdabfabcdx,t中的内容为ab时,输出结果应是:
abcdx。
当字符串中的内容为abcdabfabcdx,t中的内容为abd时,则程序输出未找到信息:
notbefound!
。
请改正程序中的错误,使它能得出正确的结果。
注意:
不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include
#include
#include
char*fun(char*s,char*t)
{
char*p,*r,*a;
/********found********/
a=NuLL;
while(*s)
{
p=s;r=t;
while(*r)
/********found********/
if(r==p)
{
r++;
p++;
}
else
break;
if(*r=='\0')
a=s;
s++;
}
returna;
}
main()
{
chars[100],t[100],*p;
clrscr();
printf("\npleaseenterstrings:
");
scanf("%s",s);
printf("\npleaseentersubstringt:
");
scanf("%s",t);
p=fun(s,t);
if(p)
printf("\ntheresultis:
%s\n",p);
else
printf("\nnotfound!
\n");
}
_
主要算法:
涉及知识点:
试题难度:
★★★
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
13.下列给定程序中,fun函数的功能是:
根据形参m,计算如下公式的值。
1111
t=1+-+-+-…+-
234m
例如,若输入5,则应输出2.283333。
请改正程序中的错误或在横线处填上适当的内容并把横线删除,使它能计算出正确的结果。
注意:
不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include
#include
doublefun(intm)
{
doublet=1.0;
inti;
/********found********/
for(i=2;i<=m;i++)
t+=1.0/k;
/********found********/
___填空____
}
main()
{
intm;
clrscr();
printf("\npleaseenter1integernumbers:
\n");
scanf("%d",&m);
printf("\n\ntheresultis%lf\n",fun(m));
}
主要算法:
涉及知识点:
试题难度:
★
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
14.下列给定程序中,函数fun和funx的功能是:
用二分法求方程2x3-4x2+3x-6=0的根,并要求绝对误差不超过0.001。
例如,若给m输入-100,给n输入90,则函数求得的一个根值为2.000。
请改正程序中的错误,使它能得出正确结果。
注意:
不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include"stdio.h"
#include"math.h"
doublefunx(d