全部知识点

第7601题

请根据以下各小题的要求设计C应用程序(包括界面和代码)。
下列给定程序中,函数fun()的功能是:将n个无序整数从小到大排序。
请改正程序指定部位的错误,使它能得到正确结果。
注意:
不要改动函数main(),不得增行或删行,也不得更改程序的结构。

/**********code.c**********/
#include <stdio.h>
void fun(int n, int *a)
{
int i,j,p,t;
for(j=0;j<n-1;j++)
{
p=j;
/**********found**********/
for(i=j+1;i<n-1;i++)
if(a[p]>a[i])
/**********found**********/
t=i;
if(p!=j)
{
t=a[j];
a[j]=a[p];
a[p]=t;
}
}
}void putarr(int n, int *z)
{
int i;
for(i=1;i<=n;i++,z++)
{
printf("%4d",*z);
if(!(i%10))
printf("\n");
}
printf("\n");
}void main()
{
int aa[20]={9,3,0,4,1,2,5,6,8,10,7},n=11;
printf("\n\nBefore sorting %d numbers:\n",n);
putarr(n,aa);
fun(n,aa);
printf("\nAfter sorting %d numbers:\n",n);
putarr(n,aa);
}
/**********-code.c**********/
第7602题

函数fun功能是:将a、b中的两个两位正整数合并形成一个新的整数放在c中。合并的方式是将a中的十位和个位数依次放在变量c的千位和十位上,b中的十位和个位数依次放在变量c的个位和百位上。
例如,当a=45,b=12。调用该函数后,c=4251。
注意,部分源程序存在文件PROG1.C中。数据文件IN.DAT中的数据不得修改。
请勿改动主函数main和其它函数中的任何内容,仅在函数fun花括号中填入你编写的若干语句。

/**********code.c**********/
#include <stdio.h>
void fun(int a, int b, long *c)
{

}
int main()
{
int a,b;
long c;
printf("Input a b:");
scanf("%d%d", &a, &b);
fun(a, b, &c);
printf("The result is: %ld\n", c);
}
/**********-code.c**********/

第7603题

下列给定程序的功能是调用fun函数建立班级通信录。通信录中记 录每位学生的编号、姓名和电话号码。班级人数和学生信息从键盘读 入,每个人的信息作为一个数据块写到名为myfile5.dat的二进制文件 中。 请在程序的下画线处填入正确的内容并将下画线删除,使程序得 出正确的结果。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的结构!

/**********code.c**********/
#include <stdio.h>
#include<stdlib.h>
#define N 5
typedef struct
{ 
 int num;
 char name[10];
 char tel[10];
}STYPE;
void check();
/**********found**********/
int fun(①______ *std)
{
 /**********found**********/ ②______ *fp; int i;
 if((fp=fopen("myfile5.dat","wb"))==NULL)return(0);
 printf("\nOutput data to file! \n");
 for(i=0;i<n;i++) **********found**********="" fwrite(&std[i],sizeof(stype),1,③______);
 fclose(fp);
 return(1);
}
void main()
{
 STYPE s[10]={ {1,"aaaaa","111111"}, {1,"bbbbb","222222"},
{1,"ccccc","333333"}, {1,"ddddd","444444"}, {1,"eeeee","555555"} };
 int k;
 k=fun(s);
 if(k==1)
 {
 printf("Succeed!");
 check();
 }
 else printf("Fail!");
}
void check()
{
 FILE *fp; int i; STYPE s[10];
 if((fp=fopen("myfile5.dat","rb"))==NULL)
 {
 printf("Fail! \n");
 exit(0);
 }
 printf("\nRead file and output to screen: \n");
 printf("\n num name tel\n");
 for(i=0;i<n;i++) { fread(&s[i],sizeof(stype),1,fp); printf("%6d%s%s\n",s[i].num, s[i].name,s[i].tel); }
 fclose(fp);
 **********-code.c**********
第7604题

下列给定程序中,函数fun的功能是:从s所指字符串中,找出t所指 字符串的个数作为函数值返回。例如,当s所指字符串中的内容为“abcdabfab”,t所指字符串的内容为“ab”,则函数返回整数3。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的 结构!

/**********code.c**********/
#include <stdlic.h>
#include <conio.h>
#include <stdio.h>
#include <string.h>
int fun(char *s, char *t)
{
 int n;
 char *p, *r;
 n=0;
 while(*s)
 {
 p=s;
 r=t;
 while(*r)
 /**********found**********/
 if(*r==*p){r++; p++}
 else break;
 /**********found**********/
 if(r=='\0')
 n++;
 s++;
 }
 return n;
}
void main()
{
 char s[100],t[100]; int m;
 system("CLS");
 printf("\nPlease enter strings:");
 scanf("%s",s);
 printf("\nPlease enter substrings:");
 scanf("%s",t);
 m=fun(s,t);
 printf("\nThe result is:m=%d\n", m);}
/**********-code.c**********/
第7605题

请编一个函数void fun(int tt[M][N],int pp[N]),tt指向一个M行N列的 二维数组,求出二维数组每列中最大元素,并依次放入pp所指的一维 数组中。二维数组中的数已在主函数中给出。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花 括号中填入你编写的若干语句。

/**********code.c**********/
#include <stdlic.h>
#include <conio.h>
#include <stdio.h>
#define M 3 
#define N 4 
void fun(int tt[M][N],int pp[N])
{ 
} void main()
{
 int t[M][N]={{68,32,54,12},{14,24,88,58},{42,22,44,56}}; 
 int p[N],i,j,k; 
 system("CLS"); 
 printf("The riginal data is:\n"); 
 for(i=0;i<m;i++) {="" for(j="0;j<N;j++)printf("%6d",t[i][j]);" printf("\n");}
fun(t,p);
 printf("\nthe result is:\n");
 for(k="0;k<N;k++)
 printf("%4d",p[k]);

第7606题

N个有序整数数列已放在一维数组中,给定下列程序中,函数fun()的功能是:利用折半查找法查找整数m在数组中的位置。若找到,则返回其下标值;反之,则返回“Not be found!”。
折半查找法的基本算法是:每次查找前先确定数组中待确定的范围:low和high(low放在中间位置之后的元素中;反之,下次查找范围落在中间位置之前的元素中。直到low>high,查找结束。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。

/**********code.c**********/
#include<stdio.h>
#define N 10
int fun(int a[],int m)
{
int low=0,high=N-1,mid;
while(low<=high)
{
/**********found**********/
mid= ①______;
if(m<a[mid])
/**********found**********/
high= ②______;
else if(m>a[mid])
low=mid+1;
else
return(mid);
}
/**********found**********/
③______(-1);
}
main()
{
int i,a[N]={-3,4,7,9,13,24,67,89,100,180},k,m;
printf("a数组中的数据如下:");
for(i=0;i<N;i++)printf("%d",a[i]);
printf("Enter m:");
scanf("%d",&m);
k=fun(a,m);
if(k>=0)
printf("m=%d,index=%d\n",m,k);
else
printf("Not be found\n");
}
/**********-code.c**********/
第7607题

下列给定程序中,函数fun()的功能是计算并输出high以内的素数之和。high由主函数传给fun()函数。例如:若high的值为100,则函数的解为1060。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。

/**********code.c**********/
#include<conio.h>
#include<stdio.h>
#include<math.h>
int fun(int high)
{
int sum=0,n=0,j,yes;
while(high>=2)
{
yes=1;
for(j=2;j<=high/2;j++)
/**********found**********/
if high%j==0
{
yes=0;
break;
}
/**********found**********/
if(yes==0)
{
sum+=high;
n++;
}
high--;
}return sum;
}
main()
{
printf("%d\n",fun(100));
}
/**********-code.c**********/
第7608题

请编写函数fun,其功能是:计算并输出3到n之间(含3和n)所有素数的平方根之和。例如,在主函数中从键盘给n输入100后,输出为:sum=148.874270。
注意:要求n的值大于2但不大于100。部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。

/**********code.c**********/
#include <math.h>
#include <stdio.h>
double fun(int n)
{

}
main()
{
int n;
double sum;
printf("\n\nInput n: ");
scanf("%d",&n);
sum=fun(n);
printf("\n\nsum=%f\n\n",sum);
}

第7609题

请补充fun函数,该函数的功能是:按‘0’到‘9’统计一个字符串中的 奇数数字字符各自出现的次数,结果保存在数组num中。注意:不能 使用字符串库函数。 例如,输入“x=1123.456+0.909*bc”,结果为:1=2,3=1,5=1,7=0,9=2。注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横 线上填入所编写的若干表达式或语句。

/**********code.c**********/
#include <conio.h>
#include <stdio.h>
#define N 20
fun(char *tt,int num[])
{
 int i,j;
 int bb[10];
 char *p=tt;
 for(i=0;i<10;i++)
 {
 num[i]=0;
 bb[i]=0;
 }
 /**********found**********/
 while(①______)
 {
 if(*p>='0'&&*p<='9')
 /**********found**********/ ②______;
 p++;
 } for(i=1,j=0;i<10;i=i+2,j++)
 /**********found**********/ ③______;
}
main()
{
 char str[N];
 int num[10],k;
 printf("\nPlease enter a string:");
 gets(str);
 printf("\n******** The original string ********\n");
 puts(str);
 fun(str,num);
 printf("\n******** The number of letter ********\n");
 for(k=0;k<5;k++)
 {
 printf("\n");
 printf("%d=%d",2*k+1,num[k]);
 }
 printf("\n");
 return;
}
/**********-code.c**********/
第7610题

下列给定程序中,函数fun()的功能是:用选择法对数组中的n个元 素按从小到大的顺序进行排序。 请改正程序中的错误,使它能得到正确结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的 结构。

/**********code.c**********/
#include <stdio.h>
#define N 20
void fun(int a[],int n)
{
 int i,j,t,p;
 for(j=0;j<n-1;j++) 
{
/********found********/
 p=j;
 for(i=j;i<n;i++)
  if(a[i]<a[p]) 
  /********found********/
  t=a[p]; 
  a[p]=a[j];
   a[j]=t;
    }
  main()
  {
   int a[N]={9,6,8,3,-1},i,m=5;
    printf("排序前的数据:");
 for(i=0;i<m;i++) printf("%d",a[i]); printf("\n"); fun(a,m); printf("排序后的数据:");
 for(i=0;i<m;i++) printf("%d",a[i]); printf("\n"); }
     **********-code.c**********
第7611题

学生的记录由学号和成绩组成,N名学生的数据已在主函数中敲入 结构体数组s中,请编写函数fun,它的功能是:按分数的高低排列学 生的记录,高分在前。 注意:部分源程序给出如下。请勿改动主函数main和其它函数中 的任何内容,仅在函数fun的花括号中填入你编写的若干语句。

/**********code.c**********/
#include <stdio.h>
#define N 16
typedef struct
{
 char num[10];
 int s;
}STREC;
void fun( STREC a[] )
{
 STREC tmp; int i,j;
 for(i = 1; i < N; i++)
 for(j = 0; j < N-1; j++)
 {
 /*请按题目要求,完成一下代码*/
 }
}
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}};
 int i;
 FILE *out ;
 fun(s);
 printf("The data after sorted :\n");
 for(i=0;i<n; i++) {
   if((i)%4==0)
   printf("\n");
   printf("%s %4d ",s[i].num,s[i].s); }
    printf("\n");
     out=fopen("out.dat","w");
     for(i=0;i<N;i++)
     {
     if((i)%4==0&&i)fprintf(out, "\n");
     fprintf(out, "%4d ",s[i].s);
 } 
      fprintf(out,"\n");
       fclose(out);
       }

第7612题

给定程序的功能是:从键盘输入若干行文本(每行不超过80个字符),写到文件myfile4.txt中,用-1作为字符串输入结束的标志。然后将文件的内容读出显示在屏幕上。文件的读写分别由自定义函数ReadText和WriteText实现。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。

/**********code.c**********/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void WriteText(FILE*);
void ReadText(FILE*);
void main()
{
FILE*fp;
if((fp=fopen("myfile4.txt","w"))==NULL)
{
printf("open fail!!\n"); exit(0);
}
WriteText(fp);
fclose(fp);
if((fp=fopen("myfile4.txt","r"))==NULL)
{
printf("open fail!!\n"); exit(0);
}
ReadText(fp);
fclose(fp);
}
/**********found**********/
void WriteText(FILE ①______)
{
char str[81];
printf("\nEnter string writh -1 to end:\n");
gets(str);
while(strcmp(str,"-1")!=0)
{
/**********found**********/
fputs(②______,fw);
fputs("\n",fw);
gets(str);
}
}void ReadText(FILE*fr)
{
char str[81];
printf("\nRead file and output to screen:\n");
fgets(str,81,fr);
while(!feof(fr));
{
/**********found**********/
printf("%s",③______);
fgets(str,81,fr);
}
}
/**********-code.c**********/
第7613题

下列给定程序中,是建立一个带头结点的单向链表,并用随机函数为各结点数据域赋值。函数fun的作用是求出单向链表结点(不包括头结点)数据域中的最大值,并且作为函数值返回。请改正程序指定部位的
错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。

/**********code.c**********/
#include<stdio.h>
#include<stdlib.h>
typedef struct aa
{
int data;
struct aa *next;
} NODE;
fun( NODE *h)
{
int max=-1;
NODE *p;
/**********found**********/
p=h;
while(p)
{
if(p->data>max)
max=p->data;
/**********found**********/
p=h->next;
}return max;
}outresult(int s,FILE *pf)
{
fprintf(pf,"\nThe max in link:%d\n",s);
}
NODE *creatlink(int n,int m)
{
NODE *h,*p,*s,*q;
int i,x;
h=p=(NODE *)malloc(sizeof(NODE));
h->data=9999;
for(i=1;i<=n;i++)
{
s=(NODE *)malloc(sizeof(NODE));
s->data=rand()%m;
s->next=p->next;
p->next=s;
p=p->next;
}
p->next=NULL;
return h;
}
outlink(NODE *h, FILE *pf)
{
NODE *p;
p=h->next;
fprintf(pf,"\nTHE LIST:\n\n HEAD");
while(p)
{
fprintf(pf,"->%d",p->data);
p=p->next;
}
fprintf(pf,"\n");
}
main()
{
NODE *head;int m;
head=creatlink(12,100);
outlink(head,stdout);
m=fun(head);
printf("\nTHE RESULT:\n");
outresult(m,stdout);
}
/**********-code.c**********/
第7614题

请编写函数fun(),该函数的功能是:计算并输出给定整数n的所有因子(不包括1和自身)之和。规定n的值不大于1000。例如,在主函数中从键盘给n输入的值为856,则输出为:sum=763。
注意:部分源程序给出如下。
请勿改动主函数main()和其他函数中的任何内容,仅在fun()函数的花括号中填入所编写的若干语句。
试题程序如下:

/**********code.c**********/
#include <stdio.h>
int fun(int n)
{

}
void main()
{
int n,sum;
printf("Input n: ");
scanf("%d",&n);
sum=fun(n);
printf("sum=%d\n",sum);
}

第7615题

下列给定的程序中,函数fun()的功能是:求出以下分数序列的前n项和。2/1,3/2,5/3,8/5,13/8,21/13,……和值通过函数值返回main()函数。例如,若输入n=5,则应输出8.391667。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横 线上填入所编写的若干表达式或语句。

/**********code.c**********/
#include <stdio.h>
#include <conio.h>
double fun(int n){
 int a=2,b=1,c,k;
 double①______;
 for(k=1;k<=n;k++)
 {
 s=s+1.0*a/b;
 c=a;
 a+=②______;
 b=c;
 }
 return(s);
}
main()
{
 int n=5;
 /**********found**********/
 printf("\nThe value of function is:%1f\n",③______);
}
/**********-code.c**********/
第7616题

给定程序中函数fun的功能是:根据整型形参m,计算如下公式的 值。

公式

例如,若m中的值为:5,则应输出:1.463611。请改正程序中的错 误,使它能得到正确结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结 构。

/**********code.c**********/
#include
double fun(int m)
{
 double y=1.0;
 int i;
 /**********found**********/
 for(i=2;i<m;i++) 
/**********found**********/
y+=1/(i*i);
return(y);
 }
 main() 
 {
  int n=5;
  printf("%\nThe result is%1f\n",fun(n));
  /**********-code.c**********/
第7617题

请编写函数fun(),该函数的功能是:移动一维数组中的内容,若数 组中有n个整数,要求把下标从p~n-1(p 例如,一维数组中的原 始内容为1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,p的值为6。移动后,一维数组的内容应为7,8,9,10,11,12,13,14,15,1,2,3,4,5,6。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花 括号中填入所编写的若干语句。

/**********code.c**********/
#include <stdio.h>
#define N 80
void fun(int*w,int p,int n)
{
}
void main()
{
 int a[N]={ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
 int i,p,n=15;
 printf("The original data:\n");
 for(i=0;i<n;i++) 
printf("%3d",a[i]);
printf("\n\nEnter p:");
scanf("%d",&p);
fun(a,p,n); 
printf("\nThe data after moving:\n");
for(i="0;i<n;i++)" 
    printf("\n\n");}

第7618题

给定程序中,函数fun的功能是:找出100至x(x≤999)之间各位上的数字之和为15的所有整数,然后输出;符合条件的整数个数作为函数值返回。
例如,当n值为500时,各位数字之和为15的整数有:159、168、177、186、195、249、258、267、276、285、294、339、348、357、366、375、384、393、429、438、447、456、465、474、483、492。共有26个。
请在程序的下划线处填入正确的内容并把下划线删除,是程序得出正确的结果。
注意:

源程序存放在考生文件夹下的BLANK1.C中。
不得增行或删行,也不得更改程序的结构!

/**********code.c**********/
#include <stdio.h>
int fun(int x)
{
int n, s1, s2, s3, t;
/**********found**********/
n=①______;
t=100;
/**********found**********/
while(t<=②______)
{
s1=t%10;
s2=(t/10)%10;
s3=t/100;
if(s1+s2+s3==15)
{
printf("%d ",t);
n++;
}
/**********found**********/
③______;
}return n;
}void main()
{
int x=-1;
while(x>999||x<0)
{
printf("Please input(0<x<=999): ");
scanf("%d",&x);
}
printf("\nThe result is: %d\n",fun(x));
}
/**********-code.c**********/
第7619题

给定程序MODI1.C中函数fun的功能:先将s所指字符串中的字符按逆序存放到t所指字符中,然后把s所指串中的字符按正序连接到t所指串的后面。
例如:当s所指的字符串为:"ABCDE"时,则t所指的字符串应为:"EDCBAABCDE"。
请改正程序中的错误,使它能得出正确的结果。
注意:

不要改动main函数,不得增行或删行,也不得更改程序的结构!

/**********code.c**********/
#include<stdio.h>
#include<string.h>
void fun (char *s, char *t)
{
/**********found**********/
int i;
i=0;
sl = strlen(s);
for(; i<sl; i++)
/**********found**********/
t[i] = s[sl-i];
for(i=0; i<sl; i++)
t[sl+i] = s[i];
t[2*sl] = '\0';
}
main()
{
char s[100],t[100];
printf("\nPlease enter string s:"); scanf("%s", s);
fun(s,t);
printf("The result is: %s\n", t);
}
/**********-code.c**********/
第7620题

给定程序中,函数fun功能是:找出100~999之间(含100和999)所有整数中各位上数字之和为x(x为一正整数)的整数.然后输出;符合条件的整数个数作为函数值返回。
例如,当x值为5时,l00~999之间各位上数字之和为5的整数有:104、113、122、131、140、203、212、221、230、302、311、320、401、410、500。共有15个。当x值为27时,各位数字之和为27的整数是:999。只有1个。
请在程序的下划线处填入正确的内容并把下划线删除.使程序得出正确的结果。
注意:

源程序存放在考生文件夹下的BLAIIK1.C中。
不得增行或删行.也不得更改程序的结构!

/**********code.c**********/
#include <stdio.h>
int fun(int x)
{
int n, s1, s2, s3, t;
n=0;
t=100;
while(t<=①______)
{
s1=t%10;
s2=(②______)%10;
s3=t/100;
if(s1+s2+s3==③______)
{
printf("%d ",t);
n++;
}
t++;
}return n;
}
void main()
{
int x=-1;
while(x<0)
{
printf("Please input(x>0): ");
scanf("%d",&x);
}
printf("\nThe result is: %d\n",fun(x));
}
/**********-code.c**********/