填空题由N个有序整数组成的数列已放在一维数组中,下列给定程序中函数fun()的功能是:利用折半查找法查找整数m在数组中的位置。若找到,返回其下标值;否则,返回-1。
折半查找的基本算法是:每次查找前先确定数组中待查的范围low和high(low<high),然后用m与中间位置(mid)上元素的值进行比较。如果m的值大于中间位置元素的值,则下一次的查找范围落在中间位置之后的元素中;反之,下一次的查找范围落在中间位置之前的元素中,直到low>high,查找结束。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
试题程序 #include
<stdio.h> #define N 10 /* * * * *found* * * *
* / void fun(int a[], int m) { int low=0,
high=N-1, mid; while(low<=high) {
mid=(low+high)/2; if(m<a[mid])
high=mid-1; /* * * * *found* * * * * / else
If(m>a[mid]) low=mid+1; else return
(mid); } return(-1);
} main() { int i,
a[N]={-3,4,7,9,13,45,67,89,100,180 }, k, m;
printf("a数组中的数据如下:"); for(i=0; i<N; i++) printf("% d",
a[i]); printf("Enter m:"); scanf("% d",
k=fun(a, m); if(k>=0) printf("m=% d, index =% d/n", m,
k); else printf("Not be found!/n"); }
填空题以下程序的输出结果是 【19】 。 #include<stdio.h> main() struct stru int a; float b; char d[4]; ; printf("%d/n",sizeof(struct stru));
填空题请写出与以下表达式等价的表达式:A.______B.______。
A.!(x>0) B.!0
填空题以下程序调用函数swap_p将指针s和t所指单元(a和b)中的内容交换,请填空。 main() int a=10,b=20,*s,*t; s=&a;t=&b; swap_p( 【13】 ); printf("%d%d,a,b"); swap_p(int**ss,int**tt) int term; term=**ss; **ss=**tt; **tt=term;
填空题下列程序的功能是输入一个整数,判断其是否是素数,若为素数则输出1,否则输出0。请填空。 #include <stdio.h> main() int i,x,y=1; scanf("%d",&x); for(i=2;i<=x/2;i++) if 【14】 y=0;break; printf("%d/n",y);
填空题有定义char a,b;若想通过&运算符保留a对应的二进制数的第3位和第6位的值,其余位置0,则b的二进制数应是 【7】 。
填空题给定程序中函数fun的功能是:从n(形参)个学生的成绩中统计出低于平均分的学生人数,此人数由函数值返回,平均分存放在形参aver所指的存储单元中。
例如,若输入8名学生的成绩:80.5 60 7290.5 98 51.5 88 64,则低于平均分的学生人数为:4(平均分为:75.5625)。
请改正程序中的错误,使它能统计出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
给定源程序:
#include <stdio.h>
#define N 20
int fun(float *s,int n,float*aver)
{float ave,t=0.0;
int count=0,k,i;
for(k=0; k<n; k++)
/**************found**************/
t=s[k];
ave=t/n;
for(i=0;i<n;i++)
if(s[i]<ave)count++;
/**************found**************/
*aver=Ave;
return count;
}
main()
{float s[30],aver;
int m,i;
printf("/nPlease enter m:");
scanf("%d",
printf("/nPlease enter %d mark :/n",m);
for(i=0;i<m;i++)scanf("%f",s+i);
printf("/nThe number of students:%d/n",fun(s,m,
printf("Ave=%f/n",aver);
}
填空题若用0至9之间不同的三个数构成一个三位数,下面程序将统计出共有多少种方法。请填空。
#include<stdio.h>
main()
{ int i,j,k,count=0;
for(i=0;i<=9;i++)
for(j=0;i<=9;j++)
if({{U}} 【18】 {{/U}})continue;
else for(k=0;k<=9;k++)
if({{U}} 【19】 {{/U}})count++;
printf("%d",count);}
填空题给定程序MODI1.C中函数fun的功能是将长整型数中每一位上为奇数的数依次取出,构成一个新数放在t中。高位仍在高位,低位仍在低位。
例如,当s中的数为87653142时,t中的数为7531。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
给定源程序如下。
#include<stdio.h>
void fun(long s,long*t)
{ int d;
long s1=1;
/*************found***********/
t=0;
while(s>0)
{ d=s%10;
/**************found************/
if(d%2==0)
{
*
t=d
*
s1+
*
t;
s1
*
=10;
}
s/=10;
}
}
main()
{ long s,t;
printf("/nPlease enter s:");scanf("%ld",
fun(s,
printf("The result is:%ld/n",t);
}
填空题给定程序的功能是:调用函数fun将指定源文件中的内容复制到指定的目标文件中,复制成功时函数返回值为1,失败时返回值为0。在复制的过程中,把复制的内容输出到终端屏幕。主函数中源文件名放在数组sfname中,目标文件名放在数组tfname中。 请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构。 文件BLANK1.C内容如下: #include<stdio.h> #include<stdlib.h> int fun(char *source,char *target) FILE *fs,*ft; char ch; /**********found**********/ if((fs=fopen(source, (1) ))==NULL)return 0; if((ft=fopen(target,"w"))==NULL)return 0; printf("/nThe data in file: /n"); eh=fgetc(fs); /**********found**********/ while(!feof( (2) )) putehar(ch); /**********found**********/ fpute(ch, (3) ); ch=fgetc(fs); fclose(fs); fclose(ft); printf("/n/n"); return 1; void main( ) char sfname[20]="myfile1",tfname[20]="myfile2"; FILE *myf; int i; char c; myf=fopen(sfname,"w"); printf("/nThe original data: /n"); for(i=1;i<30;i++) c='A'+rand( )%25; fprintf(rayf,"%c",c); printf("%c",c); fclose(myf); printf("/n/n"): if(fun(sfnaille,tfname)) printf("Succeed!"); else printf("Fail!");
填空题函数的参数是结构类型指针,则调用该函数时所提供的对应的实参可以是同类型结构变量的地址、结构指针以及______。
填空题执行下列语句段后,x的值是______。 int*p,x; x=100; p= x=*p+50;
填空题以下程序的功能是输入任意整数给n后,输出n行由大写字母A开始构成的三角形字符阵列图形。例如,输入整数5时(注意:n不得大于10),程序运行结果如下: ABCDE FGHI JKL MN O 请填空完成该程序。 main() int i,j,n; char ch='A'; scanf("%d", if(n<11) for(i=1;i<=n;i++) for(j=1;j<=n-i+1;j++) printf("%2c",ch); 【17】 ; 【18】 ; else printf("n is too large!/n") printf("/n"0);
填空题已有定义如下: struct node int data; struct node *next; *p; 以下语句调用malloc函数,使指针p指向一个具有struct node类型的动态存储空间。请填空。 p=(struct node *)malloc( 【10】 );
填空题语句printf("%f/n",13.0*(1/5));的输出结果为{{U}} {{U}} {{/U}} {{/U}}。
填空题请补充main函数,该函数的功能是:从一个字符串中截取前面若干个给定长度的子字符串。其中,str1指向原字符串,截取后的字符存放在str2所指的字符数组中,n中存放需截取的字符个数。 例如:当str1=“cdefghij”,然后输入4,则str2=“cdef”。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。 试题程序: #include<stdio.h> #include<conio.h> #define LEN 80 main() char str1[LEN],str2[LEN]; int n,i; clrscr(); printf("Enter the string:/n"); gets(str1); printf "Enter the position of the string deleted:"); scanf( 【1】 ); for(i=0;i<n;i++) 【2】 str2[i]=‘/0’; printf("The new string is:%s/n", 【3】 );
填空题下列给定的程序中,函数fun()的功能是:求出以下分数序列的前n项和。2/1,3/2,5/3,8/5,13/8,21/13,……和值通过函数值返回main()函数。例如,若输入n=5,则应输出8.391667。
注意:
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
[试题源程序]
#incúde<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;
printf("/nThe value of function is:%lf/n",______);
}
填空题下面程序的功能是建立一个有3个结点的单循环链表,然后求各个结点数值域data中数据的和,请填空。#include<stdio.h>#include<stdlib.h>structNODE{intdata;structNODE*next;};main(){structNODE*p,*q,*r;intsum=0;p=(structNODE*)malloc(sizeof(structNODE));q=(structNODE*)malloc(sizeof(structNODE));r=(structNODE*)malloc(sizeof(structNODE));p->data=100;q->data=200;r->data=300;p->next=q;q->next=r;r->next=p;sum=p->data+p->next->data+r->next->next{{U}}[19]{{/U}};printf("%d/n",sum);}
填空题以下程序中,fun函数的功能是求3行4列二维数组每行元素的最大值。请填空。 void fun(int,int,int (*)[4], int *); main() int a[3][4]=12,41,36,28,19,33,15,27),3,27,19,1,b[3],i; fun(3,4,a,B) ; for(i=0;i<3;i++)printf("%4d",b[i]); printf("/n"); void fun(int m,int n,int ar[][4],int *br) int i,j,x; for(i=0;i<m;i++) x=ar[i][0]; for(i=0;j<n;j++) if(x<ar[i][j]) x=ar[i][j]; ______=X;
填空题仅由顺序、选择(分支)和重复(循环)结构构成的程序是{{U}} (4) {{/U}}程序。