题目
第1题
下列给定函数中,函数fun()的功能是:统计字符串中各元音字母(即A,E,I,O,U)的个数。注意:字母不分大小写。例如,输入THIs is a boot,则应输出是1 0 2 2 0。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <conio.h>
include <stdio.h>
/*************found**************/
fun(char *s, int num[5])
{ int k, i=5;
for(k=0;k<i;k++)
/*************found**************/
num [i]=0;
for{;*s;s++)
{ i=-l;
/*************found**************/
switch(s)
{ case 'a': case 'A':{i=0;break;}
case 'e': case 'E':{i=1;break;}
case 'i': case 'I':{i=2;break;}
case 'o': case 'O':{i=3;break;}
case 'u': case 'U':{i=4;break;}
}
if(i>=0)
num[i]++;
}
}
main ()
{ char s1[81]; int num1[5], i;
clrscr ();
printf("\nPlease enter a string: ");
gets (s1);
fun{s1, num1);
for(i=0;i<5;i++) printf("%d",num1[i]);
printf ("\n");
}
第2题
下列给定程序中,函数fun()的功能是:从n个学生的成绩中统计出高于平均分的学生人数,人数由函数值返回,平均分存放在形参aver所指的存储单元中。例如输入8名学生的成绩:
85 65.5 69 95.5 87 55 62.5 75
则高于平均分的学生人数为4(平均分为74.312500)。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <stdio.h>
include <conio.h>
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<n;k++)
t+=s[k];
ave=t/n;
for(i=0;i<n;i++)
/*************found***************/
if(s[i]<ave)
count++;
/*************found*************/
aver=ave;
return count;
}
main()
{
float S[30],aver;
int m,i;
clrscr();
printf("\nPlease enter m:");
scanf("%d",&m);
printf("\nPlease enter%d mark:\n",m);
for(i=0;i<m;i++)
scanf("%f",s+i);
printf("\nThe number of students:%d\n",
fun(S,m,&aver));
printf(“AVe=%f\n”,aver);
}
第3题
下列给定程序中,函数fun()的功能是:从n个学生的成绩中统计出低于平均分的学生人数,此人数由函数值返回,平均分存放在形参aver所指的存储单元中。例如输入8名学生的成绩:
80.5 60 72 90.5 98 51.5 88 64
则低于平均分的学生人数为4(平均分为75.5625)。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <stdio.h>
include <conio.h>
define N 20
int fun(float *s, iht n,float *aver)
{ float ave ,t=0.0;
int count=0,k,i;
for(k=0;k<n;k++)
/*************found**************/
t=s[k];
ave=t/n;
for(i=0;i<n;i++)
if(s[i]<ave) count++;
/*************found**************/
*aver=&ave;
return count;
}
main()
{ float s[30],aver;
int m,i;
clrscr();
printf("\nPlease enter m: "); scanf
("%d",&m);
printf("\nPlease enter %d mark :\n",m);
for(i=0;i printf("\nThe number of students :
%d\n",fun(s,m,&aver));
printf("Ave=%f\n",aver);
}
第4题
例如,形参s所指的字符串为:This is a C languageprogram.,函数的返回值为6。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANKl.C中。
不得增行或删行,也不得更改程序的结构!
第5题
下列给定程序中,函数fun()的功能是:给定n个实数,输出平均值,并统计平均值以上(含平均值)的实数个数。例如, n=8时,输入193.199,195.673,195.757,196.051,196.092, 196.596,196.579,196.763,所得平均值为195.838745,在平均值以上的实数个数应为5。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <conio.h>
include <stdio.h>
int fun(float x[], int n)
/***************found*******************/
iht j, c=0;float xa=0.0;
for (j=0; j<n;.j++)
xa+=x[j]/n;
printf("ave=%f\n",xa);
for (j=0; j<n;j++)
if(x[j]>=xa)
c++;
returnc;
}
main()
{float x[l00]={ 193.199,195.673,195.757,
196.051,196.092,196.596,
196.579,196.763};
clrscr ();
printf("%d\n",fun (x,8));
}
第6题
下列给定程序中,函数fun()的功能是:依次取出字符串中所有的数字字符,形成新的字符串,并取代原字符串。
请改正函数fun()中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <stdio.h>
include <conio.h>
void fun(char *s)
{int i,j;
for(i=0,j=0; s[i]!= '\0'; i++)
if(s[i]>= '0'&&s[i]<= '9')
/*************found**************/
s[j]=s[i];
/*************found**************/
s[j]="\0";
}
main()
{char item[80];
clrscr();
printf("\nEnter a string: ");gets(item);
printf("\n\nThe string is:\%s\n", item);
fun(item);
printf("\n\nThe string of changing is :
\%s\n",item);
}
第7题
下列给定程序中,函数fun()的功能是;将s所指字符串中的字母转换为按字母序列的后续字母(但Z转化为A,z转化为 a),其他字符不变。
请改正函数fun()中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <stdio.h>
include <ctype.h>
include <conio.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)++;
}
}
main()
{ char s[80];
clrscr();
printf("\n Enter a string with length <80:\n\n");gets(s);
printf("\n The string:\n\n");puts(s);
fun(s);
printf("\n\n The Cords:\n\n");puts(s);
}
第8题
下列给定程序中,函数fun()的功能是:依次取出字符串中所有的字母,形成新的字符串,并取代原字符串。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include<stdio.h>
include<conio.h>
void fun(char*S)
{
int i,j;
for(i=0,j=0;s[i]! ='\0';i++)
/*************found************/
if((s[i]>='A'&&s[i]<='Z')&&(s[i]>= 'a'&&S[i]<='z',))
s[j++]=s[i];
/*************found*************/
s[j]=“\0”;
}
main()
{
char item[80];
clrscr();
printf(“\nEnter a string:”);
gets(item);
printf(“\n\nThe string is:\%S\n",item);
fun (item);
printf("\n\nThe string of changing
is:\%S\n",item);
}
第9题
下列给定程序中,函数fun()的功能是;求S的值。设 S=(22/1*30))*(42/(3*5))*(62/(5*7))*…*(2k)2/((2k-1)*(2k+1))
例如,当k为10时,函数的值应为1.533852。
请改正程序中的错误,使它能得出正确的结果。
注童;不要改动main 函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <conio. h>
include <stdio. h>
include <math.h >
/**************found***************/
fun (int k)
{ iht n; float s, w, p, q;
n=1;
s=1.0;
while (n<=k)
{ w=2. 0*n;
p=w-1.0;
q=w+1.0;
s=s*w*w/p/q;
n++;
}
/***************found**************/
return s
}
main()
{ clrscr ();
printf ("%f\n ", fun (10));
}
第10题
下列给定程序中,函数fun()的功能是:读入一个字符串 (长度<20),将该字符串中的所有字符按ASCII码降序排序后输出。
例如:输入dafhc,则应输出hfdca。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,敢不得更改程序的结构。
试题程序:
include <conio.h>
include <stdio.h>
/*************found**************/
int fun(char t[])
{
char c;
int i,j;
for(i=0;i<strlen(t)-1;i++)
for(j=i+1;i<strlen(t);j++)
if(t[i]<t[j])
{
c=t[j];
/*************found**************/
t[i]=t[i++];
t[i]=c;
}
}
main()
{
char s[81];
clrscr();
printf("\nPlease enter a character
string:");
gets(s);
printf("\n\nBefore sorting:\n%S",s);
fun(s);
printf("\nAfter sorting decendingly:\n
%s",s);
}
第11题
下列给定程序中,函数 fun() 的功能是:计算并输出下列级数的的N项之和SN,直到SN+1大于q为止,q的值通过形参传入。
SN=2/1+3/2+4/3+(N+1)/N
例如,若q的值为50.0,则函数值为49.394948。
请改正程序中的错误,使它能得出正确的结果。
注意;不要改动main 函数,不得增行或删行,也不得更改程序的结构.
试题程序:
include <conio.h>
include <stdio. h>
/**************found***************/
double fun(double q)
{ int n; double s,t;
n=2;
s=2.0;
while (s<=q)
{
t=s
/*************found *************/
s=s+ (n+1)/n;
n++;
}
printf ("n=%d\n ", n);
/************found***************/
return s;
}
main ()
{ clrscr();
printf ("%f\n ",fun (50));
}
为了保护您的账号安全,请在“赏学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!