简答题 C语言
题号 #2257217

下列给定程序中,函数proc()的功能是:给定n个实数,输出平均值,并统计平均值以上(含平均值)的实数个数。例如,n=8时,输入90.009,179.623,167.575,100.051,6.092,154.986,12.432,45.765,所得平均值为94.566635,在平均值以上的实数个数应为4。
请修改程序中的错误,使它能得出正确的结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
int proc(float x[],int n) //****found***-)6 int 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++:
return c;
}
void main()
{
float str[100]={  90.009,179.623,
167.575,i00.051,
6.092,154.986,
12.432,45.765);
system("CLS"):
printf("%d\n",proc(str,8));}

进入在线模考

参考答案

暂无

答案解析

错误:缺{
正确:加{
【解析】根据C语言语法规则,函数体中的所有语句应包含在符号{和}之间。因此,应在函数proc()的函数后面加上符号{。

你可能感兴趣的试题

2 请补充main()函数,该函数的功能是:把文本文件text2中的内容追加到文本文件text1的内容之后。
例如,文件text2的内容为“I’m very happy!”,文件textl的内容为“I’m a girl,”,追加之后文件textl的内容为“I’m a girl,I’m very happy”。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数main()的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#define M 80
void main()
{
FILE*fp,*fp1,*fp2;
int i;
char c[M],ch;
system("CLS");
if((fp=fopen("text1.dat","r"))==NULL)
{
printf("file text1 cannot be opened\n");
exit(0);
}
printf("\n textl contents are:\n\n");
for(i=0;(ch=fgetc(fp))!=EOF;i++)
{
c[i]=ch:
putchar(c[i]);
}
fclose(fp);
if((fp=fopen("text2.dat","r"))==NULL)
{
printf("file text2 cannot be opened\n");
exit(0);
}
printf("\n\n\nB contents are:\n\n");
for(i=0;(ch=fgetc(fp))!=EOF;i++)
{
c[i]=ch;
putchar(c[i]):
}
fclose(fp);
if((fp1=fopen("text1.dat","a")) 【1】 (fp2=
fopen("text2.dat","r")))
{
while((ch=fgetc(fp2))!=EOF)
【2】 ;
}
else
{
printf("Can not open textl text2 1\n");
}
fclose(fp2);
fclose(fp1);
printf("\n***"lew text1 contents***\n\n”);
if((fp=fopen("text1.dat","r"))==NULL)
{
printf("file text1 cannot be opened\n");
exit(0);
}
for(i=0;(ch=fgetc(fp))!=EOF;i++)
{
c[i]=ch;
putchar(c[i]):
}
【3】 ;
}
找试题 · 找答案 · 找资料 在线模考