题目详情
当前位置:首页 > 职业培训考试
题目详情:
发布时间:2024-04-05 01:43:48

[简答题]改错题 在主函数中从键盘输入若干个数放入数组中,用0结束输入并放在最后一个元素中。下列给定程序中,函数fun( )的功能是计算数组元素中值为负数的平均值(不包括0)。 例如:数组中元素的值依次为43,-47,-21,53,-8,12,0,则程序的运行结果为-25.333333。 请改正程序中的错误,使它能得到正确结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 试题程序: #include #include double fun(int x[ ]) { double sum=0.0; int c=0, i=0; /**********************found***********************/ while(x[i]==0) { if(x[i]<0) { sum=sum+x[i]; c++; } i++; } /**********************found***********************/ sum=sum/c; return sum; } main( ) { int x[1000]; int i=0; clrscr( ); printf("/nPlease enter some data(end with 0) :"); do { scanf("%d",&x[i]); }while(x[i++]!=0); printf("%f/n",fun(x)); }

更多"改错题 在主函数中从键盘输入若干个数放入数组中,用0结束输入并放在最"的相关试题:

[填空题]在主函数中,从键盘输入若干个数放入数组x中,用0结束输入但不计入数组。下列给定程序中,函数fun( )的功能是:输出数组元素中小于平均值的元素。请补充函数fun( )。
例如:数组中元素的值依次为1,2,2,12,5,15,则程序的运行结果为1,2,2,5。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun( )的横线上填入所编写的若干表达式或语句。
试题程序:
#include<conio.h>
#include<stdio.h>
void fun( 【1】 ,int n)

double sum=0.0;
double average=0.0;
int i=0;
for(i=0;i<n;i++)
 【2】
average= 【3】
for(i=0;i<n;i++)
if(x[i]<average)

if(i%5==0)
printf("/n");
printf("%d/",x[i]);

main( )

int x[1000];
int i=0;
clrscr( );
printf("/nPlease enter some data(end with 0):");
do

scanf("%d",&x[i]);

while(x[i++]!=0);
fun(x,i-1);

[填空题]在主函数中从键盘输入若干个数放入数组中,用0结束输入并放在最后一个元素中。下列给定程序中,函数fun( )的功能是计算数组元素中值为负数的平均值(不包括0)。
例如:数组中元素的值依次为43,47,-21,53,-8,12, 0,则程序的运行结果为-25.333333。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <conio.h>
#include <stdio.h>
double fun(int x[])

double sum=0.0;
int c=0,i=0;
/*************found*************/
while(x[i]==0)

if(x[i]<0)

sum=sum+x[i];
c++;

i++;

/************found***********/
sum=sum/c;
return sum;
main( )

int x[1000];
int i=0;
clrscr( );
printf("/nPlease enter some data(end with
0) :”);
do

scanf("%d",&x[i]);
while(x[i++]!=0);
printf("%f/n",fun(x));

[简答题]学生的记录由学号和成绩组成,N名学生的数据已放入主函数中的结构体数组s中,请编写函数fun,其功能是:把分数最高的学生数据放在b所指的数组中。注意:分数最高的学生可能不止一个,函数返回分数最高的学生人数。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<stdio.h>
#define N 16
typedef struct

char num[10];
int s;
STREC;
int fun(STREC*a,STREC*b)


void main( )

STREC s[N]="GA005",85,"GA003",76,"GA002",69,"GA004",85,"GA001",91,"GA007",72,"GA008",64,"GA006",87,"GA015",85,"GA013",91,"GA012",64,"GA014",91,"GA011",66,"GA017",64,"GA018",64,"GA016",72;
STREC h[N];
int i,n;
n=fun(s,h);
printf("The%d highest score:/n",n);
for(i=0;i<n;i++)
printf("%s%4d/n",h[i],num,h[i],s);/*输出最高分的学号和成绩*/
printf("/n");

[简答题]学生的记录由学号和成绩组成,M名学生的数据已在主函数中放入结构体数组stu中,请编写函数proc( ),该函数的功能是:把高于等于平均分的学生数据放在b所指的数组中,高于等于平均分的学生人数通过形参n传回,平均分通过函数值返回。
注意:部分源程序已给出。
请勿改动主函数main和其他函数中的任何内容,仅在函数proc的花括号中填入所编写的若干语句。
试题程序:
#include<stdio.h>
#define M 12
typedef struct
char num[10];
double s;
STREC;
double proc(STREC*a,STREC*b,int*n)


void main( )

STREC stu[M]=f"GA05",85,"GA03",76,
"GA02",69),"GA04",85,"GA01",91,
"GA07",72),"GA08",64,"GA06",87,
"GA09",60,"GA11",79),("GA12",73,
"GA10",90;
STREC h[M];
int i,n;
double ave;
ave=proc(stu,h,&n);
printf("The%d student data which is higher than %7.3f:/n",n,ave);
for(i=0;i<n;i++)
printf("%s%4.1f/n",h[i].num,h[i].s);
printf("/n");

[简答题]在主函数中从键盘输入若干个数放人数组中,用0结束输入并放在最后一个元素中。下列给定程序中,函数fun的功能是:计算数组元素中所有值为正数的平均值(不包括0)。
例如,数组中元素的值依次为:39、-47、21、2、-8、15、0,则程序的运行结果为19250000。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<conio.h>
#include<scdio.h>
double fun(int x[])

/********found********/
int sum=0.0;
int c=0,i=0;
while(x[i]!=0)

if(x[i]>0)

sum+=x[i];
C++;

i++;
]
/********found********/
sum/=c;
return sum;

main( )

int x[1000];
int i=0;
printf("/nPlease enter some dat a(endwith 0):");
do

scanf("%d",&x[i]);

while(x[i++]!=0);
printf("%lf/n",fun(x));

[简答题]学生的记录由学号和成绩组成,M名学生的数据已在主函数中放入结构体数组S中,请编写函数proc( ),它的功能是:把分数最高的学生数据放在h所指的数组中。注意:分数高的学生可能不只一个,函数返回分数最高学生的人数。
注意:部分源程序已给出。
请勿改动主函数main和其他函数中的任何内容。
试题程序:
#include<stdio.h>
#define M 16
typedef struct
char num[10];
int s;

STREC;
int proc(STREC * a, STREC*b)


void main( )

STREC stu[M]="GA005", 85, "GA003", 76,
"GA002", 69, "GA004", 85, "GA001", 91,
"GA007", 72, "GA008", 64, "GA006", 87,
"GA015", 85, "GA013", 91, "GA012", 64,
"GA014", 91, "GA011", 66, "GA017", 64,
"GA018", 64, "GA016", 72;
STREC h[M];
int i, n;
n=proc(stu, h);
printf("The %d highest score: /n", n);
for(i=0; i<n; i++)
printf("% S%4d/n", h[i]. num, h[i].s);
//输出最高分学生的学号和成绩
printf("/n");

[简答题]学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组s中,请编写函数fjun( ),该函数的功能是:把高于等于平均分的学生数据放在b所指的数组中,高于等于平均分的学生人数通过形参n传回,平均分通过函数值返回。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <stdio.h>
#define N 12
typede f struct
char num[10];
double s;
STREC;
double fun (STREC *a,STREC *b, int *n)


main ( )
STREC s IN] = "GA05", 85 , "GA03", 76 ,
"GA02", 69, "GA04", 85, "GA01", 91,
"GA07", 72, "GA08", 64, "GA06", 87,
"GA09", 60, "GAll", 79 , "GA12", 73,
"GA10", 90 ;
STREC h[N],t;
FILE *out;
int i ,j,n;
double ave;
ave=fun (s, h, &n);
printf("The %d student data which is
higher than %7.3f: In", n, ave);
for(i=0; i<n; i++)
printf ("%s %4.1f/n",h[i] .num, h[i] .s);
printf ("/n");
out=fopen ("out90.dat", "w");
fprintf(out, "%dkn %7.3f/n",n,ave);
for(i=0; i<n-1; i++)
for (j=i+l; j<n; j ++)

[填空题]以下程序调用fun函数把x中的值插入到a数组下标为k的数组元素中。主函数中,n存放a数组中数据的个数。请填空。 #include void fun( int s[], int *n, int k, int x) { int i; for(i=*n-1; i>=k; i- -) s[ 【14】 ]=s[i]; s[k]=x; *n=*n+ 【15】 ; } main( ) { int a[20]={1,2,3,4,5,6,7,8,9,10,11}, i, x=0, k=6, n=11; fun(a, &n, k,x); for(i=0;i
[简答题]学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组S中,请编写函数fun,其功能是:把低于平均分的学生数据放入b所指的数组中,低于平均分的学生人数通过形参n传回,平均分通过函数值返回。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<stdio.h>
#define N 8
typedef struct

char num[10];
double s;
STREC;
double fun(STREC*a,STREC*b,int*n)


void main( )

STREC s[N]="GA05",85,"GA03",76,"GA02",69,"GA04",85,"GA01",91,"GA07",72,"GA08",64,"GA06",87;
STREC h[N];
int i,n;
double ave;
ave=fun(s,h,&n);
printf("The%d student data which is lower
than%7.3f:/n"
n,ave);
for(i=0;i<n;i++)/*输出成绩低于平均值的学生记录*/
printf("%s%4.1f/n",h[i],num,h[i],s;
printf("/n");

[简答题]学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组s中,请编写函数fun( ),它的功能是:把指定分数范围之外的学生数据放在b所指的数组中,分数范围之外的学生人数由函数值返回。
例如,输入的分数是80和89,则应当把分数低于80和高于89的学生数据进行输出,不包含80分和89分的学生数据。主函数中把80放在low中,把89放在heigh中。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序
#include <stdio.h>
#define N 16
typedef struct
char num[10];
int s;
STREC;
int fun(STREC *a,STREC *b,int 1,int h)

main ( )

STREC s[N]="GA005",55,"GA003",96,
"GA002",80,"GA004",68,"GA001",88,
"GA007",74,"GA008",85,"GA006",99,
"GA015",90,"GA013",53,"GA012",66,
"GA014",82,"GA0ll",73,"GA017",69,
"GA018",64,"GA016",86;
STEC h[N],tt;
FILE *out;
int i,j,n,low,heigh,t;
printf("Enter 2 integer number low & heigh:");
scanf("%d%d",&low,&heigh);
if(heigh<low)

t=heigh;
heigh=low;
low=t;

n=fun(s,h,low,heigh);
printf("The student ’s data out%d--%d:/n",low,heigh);

我来回答:

购买搜题卡查看答案
[会员特权] 开通VIP, 查看 全部题目答案
[会员特权] 享免全部广告特权
推荐91天
¥36.8
¥80元
31天
¥20.8
¥40元
365天
¥88.8
¥188元
请选择支付方式
  • 微信支付
  • 支付宝支付
点击支付即表示同意并接受了《购买须知》
立即支付 系统将自动为您注册账号
请使用微信扫码支付

订单号:

请不要关闭本页面,支付完成后请点击【支付完成】按钮
恭喜您,购买搜题卡成功
重要提示:请拍照或截图保存账号密码!
我要搜题网官网:https://www.woyaosouti.com
我已记住账号密码