全部知识点

第7621题

绐定程序MODI1.C中函数fun的功能是:从低位开始取出长整型变量s中偶数位上的数,依次构成一个新数放在t中。高位仍在高位,低位仍在低位。
例如,当s中的数为:7654321时,t中的数为:642。
请改正程序中的错误,使它自能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!

/**********code.c**********/
#include <stdio.h>
/**********found**********/
void fun (long s, long t)
{
long sl=10;
s /= 10;
*t = s % 10;
/**********found**********/
while (s < 0)
{
s = s/100;
*t = s%10*sl + *t;
sl = sl * 10;
}
}
main()
{
long  s, t;
printf("\nPlease enter s:");
scanf("%ld", &s);
fun(s, &t);
printf("The result is: %ld\n", t);
}
/**********-code.c**********/
第7622题

学生的记录由学号和成绩组成,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);
}

第7623题

给定程序中,函数fun的功能是:将形参n中,各位上为偶数的数取出,并按原来从高位到低位的顺序组成一个新的数,并作为函数值返回。
例如,从主函数输入一个整数:27638496,函数返回值为:26846。
请在程序的下划线处埴入正确的内容并把下划线删除.使程序得出正确的结果。 

注意:

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

/**********code.c**********/
#include <stdio.h>
unsigned long fun(unsigned long n)
{
unsigned long x=0, s, i;
int t;
s=n;
i=①______;
while(②______)
{
t=s%10;
if(t%2==0)
{
x=x+t*i;
i=③______;
}
s=s/10;
}return x;
}void main()
{
unsigned long n=-1;
while(n>99999999||n<0)
{
printf("Please input(0<n<100000000): ");
scanf("%ld",&n);
}
printf("\nThe result is: %ld\n",fun(n));
}
/**********-code.c**********/
第7624题

给定程序MODI1.C中函数fun的功能是:输出M行M列整数方阵,然后求两条对角线上元素之和,返回此和数。请改正程序中的错误,使它能得出正确的结果。
注意:

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

/**********code.c**********/
#include <stdio.h>
#define M  5
/**********found**********/
int fun(int n, int xx[][])
{
int i, j, sum=0;
printf( "\nThe %d x %d matrix:\n", M, M);
for(i = 0; i < M; i++)
{
for(j = 0; j < M; j++)
/**********found**********/
printf("%f ", xx[i][j]);
printf("\n");
}for(i = 0;i < n;i++)
sum += xx[i][i]+xx[i][n-i-1];
return(sum);
}void main()
{
int aa[M][M]={{1,2,3,4,5},{4,3,2,1,0},{6,7,8,9,0},{9,8,7,6,5},
{3,4,5,6,7}};
printf("\nThe sum of all elements on 2 diagnals is %d.",fun(M,aa));
}
/**********-code.c**********/
第7625题

给定程序中,函数fun的功能是:将形参n中,各位上为偶数的数取出,并按原来从低位到高位相反的顺序组成一个新的数,并作为函数值返回。
例如,输入一个整数:27638496,函数返回值为:64862。
请在程序的下划线处填入正确的内容并把下划线删除.便程序得出正确的结果。
注意:

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

/**********code.c**********/
#include <stdio.h>
unsigned long fun(unsigned long n)
{
unsigned long x=0;
int t;
while(n)
{
t=n%10;
if(t%2==①______)
x=②______+t;
n=③______;
}return x;
}
main()
{
unsigned long n=-1;
while(n>99999999||n<0)
{
printf("Please input(0<n<100000000): ");
scanf("%ld",&n);
}
printf("\nThe result is: %ld\n",fun(n));
}
/**********-code.c**********/
第7626题

给定程序MODI1.C中函数fun功能是:将长整型数中每一位上为奇数的数依次取出,构成一个新数放在t中。高位仍在高位,低位仍在低位。
例如,当s中的数为:87653142时,t中的数为:7531。
请改正程序中的错误,使它能得出正确的结果。
注意:

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

/**********code.c**********/
#include <stdio.h>
void fun (long s, long *t)
{
int d;
long sl=1;
/**********found**********/
t = 0;
while (s > 0)
{
d = s%10;
/**********found**********/
if (d%2 == 0)
{
*t = d * sl + *t;
sl *= 10;
}s /= 10;
}
}void main()
{
long s, t;
printf("\nPlease enter s:");
scanf("%ld", &s);
fun(s, &t);
printf("The result is: %ld\n", t);
}
/**********-code.c**********/
第7627题

编写一个函数fun它的功能是:实现两个字符串的连接(使用库函数strcat),即把p2所指的字符串连接到p1所指的字符串后。
例如,分别输入下面两个字符串:FirstStrinf—SecondString
程序输出:
FirstString——SecondString
注意:部分源程序在文件PROG1.C文件中。
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。

/**********code.c**********/
#include <stdio.h>
void fun(char p1[],char p2[])
{

}
void main()
{
char s1[80],s2[40];
printf("Enter s1 and s2:\n");
scanf("%s%s",s1,s2);
printf("s1=%s\n",s1);
printf("s2=%s\n",s2);
printf("Invoke fun(s1,s2):\n");
fun(s1,s2);
printf("After invoking:\n");
printf("%s\n",s1);
}

第7628题

给定程序中,函数fun的功能是:将形参n所指变量中,各位上为偶数的数去除,剩余的数按原来从高位到低位的顺序组成一个新的数.并通过形参指针n传回所指变量。
例如:输入一个数:27638496,新的数:为739。
请在程序的下划线处填八正确的内容并把下划线删除,使程序得出正确的结果。 

注意:

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

/**********code.c**********/
#include <stdio.h>
void fun(unsigned long *n)
{
unsigned long x=0, i;
int t;
i=1;
while(*n)
{
/**********found**********/
t=*n % ①______;
/**********found**********/
if(t%2!= ②______)
{
x=x+t*i;
i=i*10;
}*n =*n /10;
}
/**********found**********/
*n=③______;
}
main()
{
unsigned long n=-1;
while(n>99999999||n<0)
{
printf("Please input(0<n<100000000): ");
scanf("%ld",&n);
}
fun(&n);
printf("\nThe result is: %ld\n",n);
}
/**********-code.c**********/
第7629题

给定程序MODI1.C中函数fun的功能是:计算n!。例如,给n输入入5,则输出l20.000000。
请改正程序中的错误,使程序能输出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。

/**********code.c**********/
#include <stdio.h>
double fun(int n)
{
double result = 1.0 ;
/**********found**********/
if n == 0
return 1.0 ;
while(n >1 && n < 170)
/**********found**********/
result *= n--
return result ;
}void main()
{
int n;
printf("Input N:");
scanf("%d", &n);
printf("\n\n%d! =%lf\n\n",n,fun(n));
}
/**********-code.c**********/
第7630题

请编写一个函数fun,它的功能是:将一个表示正整数的数字字符串转换为一个整数(不得调用C语言提供的将字符串转换为整数的函数)。例如,若输入字符串“1234”,则函数把它转换为整数值1234。
函数fun中给出的语句仅供参考。
注意:

部分源程序存在文件PROG1.C文件中。
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。

/**********code.c**********/
#include <stdio.h>
#include <string.h>
long fun(char *p)
{
int i,len;/* len为串长*/
long x=0;
len=strlen(p);
/*以下完成数字字符串转换为数字,注意字符’0’不是数字0*/

return x;
}
void main()
{
char s[6];
long n;
printf("Enter a tring:\n");
gets(s);
n = fun(s);
printf("%ld\n",n);
}

第7631题

给定程序中,函数fun的功能是:计算下式前n项的和作为函数的返 回值 

公式

例如,当形参n的值为10时,函数返回:9.612558。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得 出正确的结果。注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构!

/**********code.c**********/
 #include <stdio.h>
double fun(int n)
 {
 int i;
double s,t;
 /**********found**********/
 s=①______;
 /**********found**********/
 for(i=1; i<=②______; i++)
 {
 t=2.0*i;
 /**********found**********/
 s=s+(2.0*i-1)*(2.0*i+1)/③______;
 }
 return s;
 }
 main()
 {
 int n=-1;
 while(n<0)
 {
 printf("Please input(n>0): ");
 scanf("%d",&n); 
}
 printf("\nThe result is: %f\n",fun(n));
 }
 /**********-code.c**********/
第7632题

给定程序MODI1.C中函数fun的功能是:统计substr所指子字符串在 str所指字符串中出现的次数。 例如,若字符串为aaas lkaaas,子字符串为as,则应输出2。 请改正程序中的错误,使它能计算出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的 结构!

/**********code.c**********/
 #include <stdio.h>
int fun (char *str,char *substr)
 {
 int i,j,k,num=0;
 /**********found**********/
 for(i = 0, str[i], i++)
 for(j=i,k=0;substr[k]==str[j];k++,j++)
 /**********found**********/
 If(substr[k+1]=='\0')
 {
 num++;
 break;
 }
 return num;
 }
 void main()
 {
 char str[80],substr[80];
 printf("Input a string:") ;
 gets(str);
 printf("Input a substring:") ;
 gets(substr);
 printf("%d\n",fun(str,substr));
 }
 /**********-code.c**********/
第7633题

请编写一个函数fun,他的功能是:根据以下公式求 π的值(要求满 足精度0.0005,即某项小于0.0005时停止迭代):

公式

 程序运行后,如果输入精度0.0005,则程序输出为3.14…。 注意部分源程序存在文件PROG1.C立件中。 请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花 括号中填入你编写的若干语句。

/**********code.c**********/
#include <stdio.h>
#include <math.h>
double fun(double eps)
 {
 }
 void main()
 {
 double x;
 printf("Input eps:") ;
 scanf("%lf",&x);
printf("\neps = %lf,PI=%lf\n", x, fun(x));
 }

第7634题

给定程序中,函数fun的功能是:计算下式前n项的和作为函数值返 回。

公式

 例如,当形参n的值为10时,函数返回:-0.204491。 请在程序的下划线处填入正确的内容并把下划线删除.使程序得 出正确的结果。注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构!

/**********code.c**********/
 #include <stdio.h>
double fun(int n)
 {
 int i, k;
 double s, t;
 s=0;
 /**********found**********/
 k=①______;
 for(i=1; i<=n; i++) 
{
 /**********found**********/
 t=②______;
 s=s+k*(2*i-1)*(2*i+1)/(t*t);
 /**********found**********/
 k=k*③______;
 }
 return s;
 }
 void main()
 {
int n=-1;
 while(n<0)
 {
 printf("Please input(n>0): ");
 scanf("%d",&n);
 }
 printf("\nThe result is: %f\n",fun(n));
 }
 /**********-code.c**********/


第7635题

给定程序MODI1.C中函数fun的功能是:判断一个整数是否是素 数,若是返回1,否则返回0。在main()函数中,若fun返回1输出YES, 若fun返回0输出NO! 诸改正程序中的错误,使它能得出正确的结果。 注意:不要改动main函数。不得增行或删行,也不得更改程序的 结构!

/**********code.c**********/
 #include <stdio.h>
int fun(int m)
{
 int k = 2;
 while(k <= m && (m%k))
 /**********found**********/
 k++
 /**********found**********/
 if(m = k)
 return 1;
 else return 0;
 }
 void main()
 {
 int n;
 printf("\nPlease enter n: ");
 scanf("%d", &n);
 if (fun(n)) 
printf("YES\n");
 else
 printf("NO!\n");
 }
 /**********-code.c**********/


第7636题

请编写一个函数fun,它的功能是:找出一堆整型数组元素中最大 的值和它所在的下标,最大的值和它所在的下标通过形参传回。数组 元素中的值己在主函数中赋予。 主函数中x是数组名,n是x中的数据个数,max存放最大值,index存 放最大值所在元素的下标。 注意部分源程序存在文件PROG1.C 文件中。 请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花 括号中填入你编写的若干语句。

/**********code.c**********/
#include <stdlib.h>
#include <stdio.h>
void fun(int a[],int n ,int *max,int *d)
 {
 }
 void main()
 {
 int i,x[20],max,index,n=10;
 for(i=0;i < n;i++)
 {
 x[i] = rand()%50; 
printf("%4d",x[i]);
 }
 printf("\n");
 fun(x,n,&max,&index);
 printf("Max =%5d,Index =%4d\n",max,index);
 }

第7637题

给定程序中,函数fun的功能是计算下式:

公式1

 直到 

公式2

并把计算结果作为函数值返回。 例如:若形参e的值为1e-3,函数的返回值为0.141457。 请在程序的下划线处填入正确的内容并把下划线删除.使程序得 出正确的结果。注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构!

/**********code.c**********/
 #include <stdio.h.
double fun(double e)
 {
int i,k;
 double s,t, x;
 s=0;
 k=1;
 i=2;
 x=①______/4;
 while(x ②______ e)
 {
 s=s+k*x;
 k=k* (-1);
 t=2*i;
 x=③______/(t*t);
 i++;
 }
 return s;
 }
 main()
 { 
double e=1e-3;
 printf("\nThe result is: %f\n",fun(e));
 }
 /**********-code.c**********/
第7638题

下列给定的程序中,函数fun()的功能是:求出以下分数序列的前n 项和。2/1,3/2,5/3,8/5,13/8,21/13,……和值通过函数值返回 main()函数。例如,若输入n=5,则应输出8.391667。 注意:部分源程序给出如下。 请改正程序中的错误,使它能计算出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的 结构!

/**********code.c**********/
 #include <stdio.h>
/**********found**********/
 void fun(int n)
 {  
int a, b, c, k;
 double s;
 s = 0.0;
 a = 2;
 b = 1;
 for(k = 1; k <= n; k++)
 {
 /**********found**********/
 s = s + (Double)a / b;
 c = a;
 a = a + b;
 b = c;
 }
 return s;
 }
 void main()
 {   
int n = 5;
 printf("\nThe value of function is: %lf\n", fun(n));
 }
 /**********-code.c**********/
第7639题

请编写一个函数fun,它的功能是:求出一个2×M整型二维数组中 最大元素的值,并将此值返回调用函数。注意部分源程序存在文件 PROG1.C文件中。 请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花 括号中埴入你编写的若干语句。

/**********code.c**********/
#include <stdio.h>
#define M 4
 int fun (int a[][M])
 {
 }
 void main()
 { 
int arr[2][M]={5,8,3,45,76,-4,12,82};
 printf("max =%d\n", fun(arr));
 }

第7640题

给定程序中,函数fun的功能是:将a所指4×3矩阵中第k行的元素与第0行元素变换。例如,有下列矩阵:

1       2      3

4       5      6

7       8      9

10     11     12

若k为2,程序执行结果为:

7         8         9

 4        5         6

 1        2          3

 10      11       12

  请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。

  注意:源程序存放在考生文件夹下的BLANK1.C中。

  不得增行或删行,也不得更改程序的结构!

/**********code.c**********/
 #include<stdio.h>
 #define N 3
 #define M 4
 /**********found**********/
 void fun(int (*a)[N],int ①______)
 {
 int i,temp ;
 /**********found**********/
 for(i=0;i < ②______;i++)
 {
  temp=a[0][i] ;
  /**********found**********/
  a[0][i] = ③______;
  a[k][i] = temp;
 }
 }
 void main()
 {
 int x[M][N]={{1,2,3},{4,5,6},{7,8,9},{10,11,12}},i,j;
 printf("The array before moving:\n\n");
 for(i=0;i<M;i++)
 { 
  for(j=0;j<N;j++) printf("%3d",x[i][j]);
  printf("\n\n");
 }
 fun(x,2);
 printf("The array after moving:\n\n");
 for(i=0;i<M;i++)
 { 
for(j=0;j<N;j++) printf("%3d",x[i][j]);
 printf("\n\n");
 }
 }
 /**********-code.c**********/