问答题程序通过定义学生结构体变量,存储了学生的学号、姓名和3门课的成绩。函数fun的功能是对形参b所指结构体变量中的数据进行修改,最后在主函数中输出修改后的数据。
例如: b所指变量t中的学号、姓名、和三门课的成绩依次是: 10002、"ZhangQi"、93、85、87,修改后输出t中的数据应为:10004、" LiJie "、93、85、87。
请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
#include
struct student {
long sno;
char name[10];
float score[3];
};
void fun( struct student *b)
{ int i;
/**********found**********/
b__1__ = 10004;
/**********found**********/
strcpy(b__2__, "LiJie");
}
main()
{ struct student t={10002,"ZhangQi", 93, 85, 87};
int i;
printf("/n/nThe original data :/n");
printf("/nNo: %ld Name: %s/nScores: ",t.sno, t.name);
for (i=0; i<3; i++) printf("%6.2f ", t.score[i]);
printf("/n");
/**********found**********/
fun(__3__);
printf("/nThe data after modified :/n");
printf("/nNo: %ld Name: %s/nScores: ",t.sno, t.name);
for (i=0; i<3; i++) printf("%6.2f ", t.score[i]);
printf("/n");
}
问答题给定程序MODI1.C中函数fun的功能是:计算S所指字符串中含有t所指字符串的数目,并作为函数值返回。 请改正函数fun中指定部位的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!1 #include<stdio.h>2 #include<string.h>3 #define N 804 int fun(char *s,char *t)5 { int n;6 char *p,*r;7 n=0;8 while(*s)9 { p=s;10 /**********found**********/11 r=p;12 while(*r)13 if(*r==*p) { r++; p++;}14 else break;15 /**********found**********/16 if(*r=0)17 n++;18 s++;19 }20 return 0;21 }22 main()23 { char a[N],b[N];int m;24 printf(''\nPlease enter stringa:'');gets(a);25 printf(''\nPlease enter substring b:'');gets(b);26 m=fun(a,b);27 printf(''\nThe result is :m=%d\n'',m);28 }
问答题改错题
下列给定程序中,函数fun()的功能是:依次取出字符串中所有的字母,形成新的字符串,并取代原字符串。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include
#include
void fun(char *s)
{
int i,j;
for(i=0,j=0; s[i]!= ''/0''; i++)
/**********************found***********************/
if((s[i]>= ''A''
/**********************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);
}
问答题下列给定程序中,函数fun的功能是:求出S所指字符串中最后一次出现的t所指字符串的地址,并通过函数值返回,在主函数中输出从此地址开始的字符串;若未找到,则函数值为NULL。
例如,当字符串中的内容为“abcdabfabcdx”,t中内容为“ab”时,输出结果应是“abcdx”。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
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++;}
return a;
}
void main()
{
char s[100],t[100],*p;
system("CLS");
printf("\nPlease enter string S:");
scanf("%s",s);
printf("\nPlease enter substring t:");
scanf("%s",t);
p=fun(s,t);
if(p)
printf("\nThe result is:%s\n",p);
else
printf("\nNot found!\n");
}
问答题从键盘上输出10个整数存入一维数组中,按由大到小的顺序输出。
问答题给定程序MODI1. C中函数fun的功能是:将长整型数s中每一位上为偶数的数依次取出,构成一个新数放在t中。高位仍在高位,低位仍在低位。
例如,当s中的数为:87653142时,t中的数为:8642。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
#include <stdio. h>
void fun (long s, long *t)
{ int d;
long s1=1;
*t=0;
while(s>0)
{ d=s%10;
/************found************/
if(d%2=0)
{ *t=d* s1+ *t;
s1 *=10;
}
/************found************/
s/=10;
}
}
main( )
{long s, t;
printf("/nPlease enter s:");
scanf("%1d",
fun(s,
printf("The result is: %1d/n", t);
}
问答题填空题
请补充函数fun(),该函数的功能是判断一个数的个位数字和百位数字之和是否等于其十位上的数字,是则返回“yes!”,否则返回“no!”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
#include
#include
char *fun(int n)
{
int g,s,b;
g=n%10;
s=n/10%10;
b=【1】;
if((g+b)==s)
return【2】;
else
return【3】;
}
main()
{
int num=0;
clrscr();
printf("******Input data *******/n");
scanf("%d",
printf("/n/n/n");
printf("****** The result *******/n");
printf("/n/n/n%s",fun(num));
}
问答题某学生的记录由学号、8门课程成绩和平均分组成,学号和8门课程的成绩已在主函数中给出,请编写函数fun,其功能是:求出该学生的平均分,并放入记录的ave成员中。例如,学生的成绩是:85.5,76,69.5,85,91,72,64.5,87.5,则他的平均分应为78.875。注意:部分源程序给出如下。请勿改动主函数main和其他函数中的任何内容,仅在函数fun部位中填入你编写的若干语句。试题程序:#include<stdio.h>#clefine N 8typedef struct{ char num[10]; double s[N]; double ave;}STREC;void fun(STREC*a){}void main(){ STREC s={"GA005",85.5,76,69.5,85,91,72,64.5,87.5); int i; fun(&s); printf("The%s's student data:\n",s.num); for(i=0;i<N;i++) printf("%4.1 f\n",s.s[i]); printf("\nave=%7.3f\n",s.ave);}
问答题编写函数fun(),其功能是:求出1~1000中能被7或11整除,但不能同时被7和11整除的所有整数,并将其放在a所指的数组中,通过n返回这些数的个数。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数fun()的花括号中填入所编写的若干语句。
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
void fun(int*a,int*n)
{
}
void main()
{
int aa[1000],n,k;
system("CLS");
fun(aa,
for(k=0;k<n;k++)
if((k+1)%10==0)
{printf("%5d",aa[k]);
printf("/n");}//一行写9个数
else
printf("%5d",aa[k]);
printf("/n");
}
问答题若a的值小于100,请将以下选择结构改写成由switch语句构成的选择结构。
if(a<30) m=1;
else if(a<40) m=2;
else if(a<50) m=3;
else if(a<60) m=4;
else m=5;
问答题下列给定程序中,函数fun的功能是:删除指针P所指字符串中的所有空白字符(包括制表符、回车符及换行符)。 输入字符串时用“#”结束输入。 请改正程序中的错误,使它能输出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构! 试题程序:#include < string.h >#include < stdio.h >#include < ctype.h >fun(char*p){ int i,t;char C[80];/*********found*********/ For(i=0,t=0 ;p[i];i++) if(!isspace(*(p+i))) C[t++]=p[i];/*********found*********/ C[t]="/0"; strcpy(p,c);}void main(){ char c,s[80]; int i=0; printf("Input a string:"); C=getchar(); while(C!='#') {s[i]=c;i++;c=getchar();} S[i]='/0'; fun(s); puts(s);}
问答题编写函数fun,它的功能是:求小于形参n同时能被3与7整除的所有自然数之和的平方根,并作为函数值返回。例如,若n为1000时,程序输出应为:s=153.909064。
注意:
部分源程序在文件PROG1.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
[试题源程序]
#include<math.h>
#include<stdio.h>
double fun(int n)
{
}
main()/*主函数*/
{void NONO();
printf("s=%f/n",fun(1000));
NONO();
}
void NONO()
{/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/
FILE*fp,*wf;
int i,n;
double s;
fp=fopen("in.dat","r");
wf=fopen("out.dat","w");
for(i=0;i<10;i++){
fscanf(fp,"%d",
s=fun(n);
fprintf(wf,"%f/n",s);
}
fclose(fp);
fclose(wf);
}
问答题请编写函数proc(),它的功能是计算:
s=(ln(1)+ln(2)+ln(3)+…+ln(m))0.5
在C语言中可调用log(n)函数求ln(n)。
例如,若m的值为30,则proc()函数值为8.640500。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
#include<math.h>
double proc(int m)
{
}
void main()
{
system("CLS");
printf("%f/n",proc(30));
}
问答题下列给定程序中,函数fun()的功能是:通过某种方式实现两个变量值的交换,规定不允许增加语句和表达式。例如变量a中的值原为8,b中的值原为3,程序运行后a中的值为3, b中的值为8。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 试题程序: #include<conio.h> #include <stdio.h> int fun(int *x,int y) int t; /***************found***************/ t=x;x=y; /***************found***************/ return(y); main() int a=3,b=8; clrscr(); printf("%d %d/n",a, b); b=fun(&a,b); printf("%d %d/n" ,a,b);
问答题学生的记录由学号和成绩组成,N名学生的数据已放入主函数中的结构体数组s中,请编写函数fun,其功能是:把分数最高的学生数据放在b所指的数组中。注意:分数最高的学生可能不止一个,函数返回分数最高的学生人数。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。 试题程序:#include < stdio.h >#define N 1 6typedef struct{ char hum[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",77},{"GA017",64},{"GA018",64},{"GA016",72}}; STREC h[N]; int i,n; n=fun(s,h); printf("The%d highestscore:/n",n); for(i=0;i < n;i++) printf("%s%4d/n",h[i].nHin,h[i].s);/*输出最高分学生的学号和成绩*/ printf("/n");}
问答题给定程序MODI1.C中函数fun的功能是:按以下递归公式求函数值。例如,当给n输入5时,函数值为18;当给n输入3时,函数值为14。请改正程序中的错误,使它能得出正确结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。1#include<stdio.h>2/**********found**********/3intfun(n)4{intc;5/**********found**********/6if(n=1)7c=10;8else9c=fun(n-1)+2;10return(c);11}12main()13{intn;14printf(''Entern:'');scanf(''%d'',&n);15printf(''Theresult:%d\n\n'',fun(n));16}
问答题下列给定的程序中,函数proc()的功能是:用选择法对数组中的n个元素按从大到小的顺序进行排序。
请修改程序中的错误,使它能得出正确的结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<stdio.h>
#define M 20
void proc(int a[], int n)
{
int i, j, t, p;
for(j=0; j<n-1; j++)
//****found****
{ p=j
for(j=j; i<n; i++)
if(a[i]<a[p])
//****found****
p=j;
t=a[p]; a[p]=a[j]; a[j]=t;
}
}
void main()
{
int arr[M]={9, 6, 8, 3, -1}, i, m=5;
printf("排序前的数据:");
for(i=0; i<m; i++)printf("%d", arr[i]);
printf("/n");
proc(arr, m);
printf("排序后的顺序:");
for(i=0; i<m; i++)printf("%d", arr[i]);
printf("/n");
}
问答题下列给定程序中函数fun的功能是:从整数10到55之间,查找能被3整除且有一位上的数值是5的数,把这些数放在b所指的数组中,这些数的个数作为函数值返回。规定函数中a1放个位数,a2放十位数。请改正程序中的错误,使它能得出正确的结果。注意:部分源程序在文件MODI1.C中,不得增行或删行,也不得更改程序的结构!#include<stdio.h>int fun(int*b){int k,a1,a2,i=0;for(k=10;k<=55;k++){/**********found**********/a2=k/10;a1=k-az*10;if((k%3==0&&a2==5)||(k%3==0&&a1==5)){b[i]=k;i++;}}/**********found**********/return k;}main(){int a[100],k,m;m=fun(a);printf("The result is:\n");for(k=0;k<m;k++)printf("%4d",a[k]);printf("\n");}
问答题给定程序中,函数fun的功能是:计算形参x所指数组中N个数的平均值(规定所有数均为正数),将所指数组中小于平均值的数据移至数组的前部,大于等于平均值的数据移至x所指数组的后部,平均值作为函数值返回,在主函数中输出平均值和移动后的数据。
例如,有10个正数:46 30 32 40 6 17 45 15 48 26,平均值为:30.500000
移动后的输出为:30 6 17 15 26 46 32 40 45 48
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
#include
#include
#define N 10
double fun (double *x)
{ int i,j; double av,y[N];
av=0;
i=0;
while (i=0)
}
}
main ()
{ char sl[81]; int numl[5],1;
printf ( "/nPlease enter a string:
fun (s1, num1) ;
for (i=0; i < 5; 1++) printf ("%d
",num1[i] ) ; printf ("/n") ;
}
问答题给定程序中,函数fun的功能是:
找出NxN矩阵中每列元素中的最大值,并按顺序依次存放于形参b所指的一维数组中。
请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。
注意:部分源程序在文件BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include < stdio.h >
#define N 4
void fun (int (*a) [N], int *b)
{ int i,j;
for(i=0;i < N;i++) {
/*********found*********/
b[i]=
【1】
;
for(j=1;j < N;j++)
/*********found*********/
if (b[i]
【2】
a[j][i])
b[i]=a[j][i];
}
}
main()
{int x[N][N]={{12,5,8,7},
{6,1,9,3),{1,2,3,4),{2,8,4,3}},
y[N],i];
printf ("/nThe matrix :/n") ;
for(i=O;i < N;i++)
{for(j=0;j < N;j++)
printf (f'% 4d",x[i] [jl) ;
printf ("/n") ;
}
/*********found*********/
fun (
【3】
);
printf ("/nThe result is:") ;
for(i=0;i < N;i++)
printf ("%3d",y[i]) ;
printf ("/n") ;
}