请补充main函数,该函数的功能是:输出方程组“A+B=56,A+2B=72”的一组正整数解。本题的结果是: A=40,B=16。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在 main函数的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio. h>
main( )

int i, j;
clrscr ( );
for(i=0;i<100; i++)
for (j=0; j<100; j++)
if( 【1】 )
printf ("A=%2d,B=%2d", 【2】 );

[A] i+j==EF&&i+B*j==GB
[B] i,j

下列给定程序中,函数fun( )的功能是:用冒泡法对6个字符串按由小到大的顺序进行排序。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构.
试题程序:
#include <conio.h>
#include <stdio.h>
#define MAXLINE 20
/*************found**************/
fun(char *pstr[6])
int i, j;
char *p;
for(i=0;i<5;i++)
for(j=i+l;j<6;j++)
/*************found**************/
if(strcmp(*(pstr+i),pstr+j)>0)

p=*(pstr+i);
/*************found**************/
* (pstr+i) -pstr+j;
* (pstr+j)=p;




main ( )
int i;
char *pstr[6],str[6][MAXLINE];
clrscr( );
for(i=0;i<6;i++) pstr[i]=str[i];
printf("/nEnter 6 string(1 string at each
line):/n ");
for(i=0;i<6;i++) scanf("%s",pstr[i]);
fun(pstr);
printf("The strings after sorting:/n ");
for(i=0;i<6;i++) printf("%s/n ",pstr[i]);

错误: fun(char *pstr[F]) 正确: void fun(char *pstr[F])
(B) 错误: if(strcmp(*(pstr+i),pstr+j)>0 正确: if(strcmp(*(pstr+i),*(pstr+j))>0
(C) 错误: *(pstr+i)=pstr+j; 正确: *(pstr+i)=*(pstr+j);

已知学生的记录由学号和学习成绩构成,N名学生的数据已存入a结构体数组中。请编写函数fun( ),该函数的功能是;找出成绩最高的学生记录,通过形参返回主函数(规定只有一个最高分)。已给㈩函数的首部,请完成该函数。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include<stdio.h>
#include<string.h>
#include<conio.h>
#define N 10
typedef struct ss /*定义结构体*/
char num[10];
int s;
STU;
fun(STU a[], STU *s)


main ( )

STU a[N]= "A01",81, "A02",89,
"A03",66, "A04",87, "A05",77,
"A06",90, "A07",79, "A08",61,
"A09",80, "A10",71,m;
int i;
clrscr ( );
printf("*****The original data*****");
for (i=0; i<N; i++)
printf("No=%s Mark=%d/n", a[i].hum,
a[i].s);
fun (a, &m);
printf ("*****THE RESULT*****/n");
printf("The top :%s, %d/n",m.num, m.s);

fun(STU a[], STU *s)
{
int i;
*s=a[0];
for (i=0; i<N; i++) /*找出成绩最高的学生记录*/
if (s->s<a [i].s)
*s==a [i];
}

请补充main函数,该函数的功能是:从键盘输入一组字符串,以‘*’结束输入,并显示出这个字符串。
例如,输入abcdefghi*,结果显示adcdefghi。
注意:部分源程序给出如下.
请勿改动主函数main和其他函数中的任何内容,仅在 main函数的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio. h>
#define N 80
main ( )

iht i=-l, j=0;
char str IN];
clrscr ( );
printf("/n Input a string /n");
do

i++;
scanf(【1】);
while(【2】);
printf ("/n**display the string** /n");
while (j<i)

printf (【3】);
j++;

[1]"%c",&str[i] [2]str[i]!=’*’ [3]"%c",str[j]

给定程序中,函数fun( )的功能是:使数组中的元素的值增加10倍。
改正其中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构.
试题程序:
#include<stdio.h>
#include<conio.h>
iht m[10];
void fun(void)

int j;
printf("In subfunc after calling/n");
for(j=0;j<l0;j++)

/************found**********************/
printf("%3d",m[j]*l0);


main( )
int i;
printf("In main before calling/n");
for (i=0; i<10; i++)

m[i]=i;
printf ("%3d",m[i]);

fun ( );
printf("/nIn main after calling/n");
for (i=0; i<10; i++)
printf ("%3d",m[i]);
getch ( );

错误:printf("%3d" m[j]*10); 正确:printf("%3d" m[j]=m[j]*10

请编写函数fun( ),其功能是:计算并输出给定10个数的方差。 其中 例如,给定的10个数为95.0,89.0,76.0,65.0,88.0, 72.0,85.0,81.0,90.0,56.0,则输出为S=11.730729。 注意;部分源程序给出如下. 请勿改动主函数mam和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 试题程序: #include<math.h> #include<stdio.h> double fun(double x[10]) main( ) double s,x[i0]=95.0,89.0,76.0,65.0, 88.0,72.0,85.0,81.0,90.0,56.0; int i; printf("/nThe original data is:/n"); for(i=0;i<10;i++) printf("%6.1f ",x[i]); printf("/n/n "); s=fun(x); printf("s=%f/n/n ",s);

double fun(double x[A0])
{
double xl=0.0,s=0.0;
int i;
for(i=0;i<A0;i++)
xl=xl+x[i];
xl-xl/A0;                        /*求A0个数的平均值*/
for(i=0;i<l0;i++)
s=s+(x[i]-xl)*(x[i]-xA);
return sqrt(s/l0);                    /*求A0个数的方差*/
}

请补充main函数,该函数的功能是:计算每个学生成绩的平均分,并把结果保存在数组bb中。
例如,当scorer[N][M]=83.5,82,86,65,67),80,91.5,84, 99,95)90.5,95,86,95,97时,三个学生的平均分为76.7 89.9 92.7。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在 main函数的横线上填入所编写的若千表达式或语句。
试题程序:
#include<stdio.h>
#define N 3
#define M 5
main( )

int i,j;
static float score[N][M]=83.5,82,86,
65,67,80,91.5,84,99,95,90.5,95,
86,95,97;
float bb[N];
clrscr( );
for(i=0;i<N;i++)
【1】;
for(i=0;i<N;i++)

for (j=0; j<M; j++)
【2】;
bb [i]/=M;

for (i=0; i<N; i++)
print f (" knstudent %d/t average
=%5.1f",i+l,bb[i]);

[1]bb[i]=0 [2]bb[i]+=score[i][j]

以下程序可把输入的十进制数以十六进制数的形式输出。
请在横线上填上适当的内容并把横线删除,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序;
main ( )

char b[17]="0123456789ABCDEF";
int c[64] ,d,i=0,base=16;
long n;
printf("Enter a number:/n");
scanf ("%ld", &n);
do
/*****************found****************/
c[i]=______; i++; n=n/base;
while (n!=0);
printf("Transmite new base:/n");
for(--i;i>=0;--i)
/***************found*******************/
d=c[i];printf("%c",b______);
printf("/n");

错误:缺少语句 正确:应填入n%base或%16
(2)错误:缺少语句 正确:应填入[d]

学生的记录由学号和成绩组成,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 ++)
if (h[i] .s<h[j ] .s)
t=h Ii] ;h[i]=h[j] ;h[j]=t;
/*分数从高到低排列*/
for(i=0; i<n; i++)
fprintf(out, "%4.1f/n",h[i] .s);
fclose (out);

double fun (STREC *a, STREC *b, int *n)
{
int i;
double ay=0.0;
*n=0;
for(i=0;i<N;i++)
av=av+a[i].s;
ay=ay/N; /*求平均值*/
for(i=0;i<N;i++)
if(av<=a[i].s)
{ b[*n]=a[i];*n-*n+l;} /*将高于等于平均分的学生存从所指存储单元中,并统计人数*/
return ay; /*返回严均分*/
}

请补充函数fun( ),该函数的功能是将字符串tt中的大写字母都改为对应的小写字母,其他字符不变。例如,若输入“Are you come from Sichuan”,则输入“are you come from sichuan”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun( )的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#include<string.h>
#include<conio.h>
char *fun(char tt[])

int i;
for(i=0;tt[i];i++)

if((tt[i]>=’A’)&&( 【1】 ))
【2】 ;

return ( 【3】 ) ;
main( )

char tt[81];
printf("/nPlease enter a string:");
gets(tt);
printf("/nThe result string is: /n%s",
fun(tt));

[1] tt[i]<=’Z’ [2] tt[i]+=32 [3] tt

微信扫码获取答案解析
下载APP查看答案解析