填空题(在每对/**/之间填写内容,完成题目的要求)
填空题以下程序运行后的输出结果是{{U}} 【8】 {{/U}}。
main( )
{ int x=10,y=20,t=0;
if(x= =y)t=x;x=y;y=t
printf("%d,%d/n",x,y);
}
填空题以下程序的输出结果是______。
#include<stdio.h>
main()
{ int x=10,y=10;
printf("%d%d/n",x--,--y);
}
填空题以下函数rotate的功能是:将a所指N行N列的二维数组中的最后一行放到b所指二维数组的第0列中,把a所指二维数组中的第0行放到b所指二维数组的最后一列中,b所指二维数组中的其他数据不变。
#define N 4
void rotate(int a[][N],int b[][N]
{int i,j;
for(i=0;i<N;i++)
{b[i][N-1]=【 】;【 】=a[N-1][i];}
}
填空题mystrlen函数的功能是计算str所指字符串的长度,并作为函数值返回。请填空。
int mystrlen(char*str)
{ int i;
for(i=0;{{U}} 【14】 {{/U}}!='/0';i++);
return(i);}
填空题已有定义:double*p;,请写出完整的语句,利用malloc函数使p指向一个双精度型的动态存储单元{{U}} 【4】 {{/U}}。
填空题在给定程序中,函数fun()的功能是将形参指针所指结构体数组中的3个元素按num成员进行升序排列。请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 #include<stdio.h> #define N 8 typedef struct int num; int year,month,day; STU; int fun(STU *std,STU *k,int year) inti,n=0; for(i=0;i<N;i++) /**********found**********/ If( (1) ==year) /**********found**********/ k[n++]= (2) ; /**********found**********/ return( (3) ); main() STU std[N=1,1984,2,15,2,1983,9,21,3,1984,9,1,4,1983,7,15,5,1985,9,28,6,1982,11,15,7,1982,6,22), 8,1984,8,19; STU k[N];int i,n,year; printf("Enter a year:");scanf("%d", n=fun(std,k,year); if(n==0) printf("/nNo person was born in%d/n",year); else printf("/nThese persons were born in%d/n",year); for(i=0;i<n;i++) printf("%d %d-%d-%d/a", k[i].Num,k[i].year,k[i].month, k[i].day);
填空题下面程序的功能是:计算1~10之间奇数和及偶数之和。
#include <stdio.h>
main ( )
{ int a, b, c, i;
a=c=O;
for (i=O; i<=10;i+=2)
{ a+=i;
________
;
c+=b;
}
printf("偶数之和=%d/n",a);
printf("奇数之和=%d/n",c-11);
}
填空题以下函数rotade的功能是:将a所指N行N列的二维数组中的最后一行放到b所指二维数组的第0列中,把a所指二维数组中的第0行放到b所指二维数组的最后一列中,b所指二维数组中其他数据不变,请填空。 #define N 4 void rotade(int a[][N], int b[][N]) int I,j; for(I=0;I<N;I++) b[I][N-1]=______; ______=a[N-1][I];
填空题有以下程序: #include<stdio.h> #include<string.h> main() char a[]='a','b','c','d','e','f','h','/0';int i,j; i=sizeof(a);j=strlen(a); printf("%d,%d",i,j); 程序运行后的输出结果是______。
填空题以下程序运行后的输出结果是______。main() char c; int n=100; loat f=10; double x; x=f*=n/=(c=50); printf("%d %f\n",n,x);
填空题有以下程序: float f1(float n) return n*n; float f2(float n) return 2*n; main() float(*p1)(float),(*p2)(float),(*t)(float),y1,y2; p1=f1;p2=f2; y1=p2(p1(2.0)); t=P1;p1=p2;p2=t; y2=p2(p1(2.0)); printf("%3.0f,%3.0f//n",y1,y2); 程序运行后的输出结果是{{U}} {{/U}}。
填空题以下函数把b字符串连到a字符串的后面,并返回a中新字符串的长度,请填空。 strcen(char a[],char b[]) int num=0,n=0; while(*(a+num)!= 【13】 )num++; while(b[n])*(a+num)=b[n];num++; 【14】 ; return num;
填空题下列给定程序中,函数fun()的功能是进行数字字符转换。若形参ch中是数字字符‘0’~‘9’,则将‘0’转换成‘9’,‘1’转换成‘8’,‘2’转换成‘7’,…,‘9’转换成‘0’;若是其他字符则保持不变。并将转换后的结果作为函数值返回。
请在标号处填入正确的内容,使程序得出正确的结果。 注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构。
试题程序 #include
<stdio.h> ______ fun(char ch) {
if(ch>='0'
return ch; } main() {
char c1, c2; printf("/nThe result:/n");
c1='2'; c2=fun(c1); printf("c1=% cc2 =% c/n" c1, c2);
c1='8'; c2=fun(c1); 17 printf("c1=% cc2=% c/n", c1, c2);
c1='a'; c2=fun(c1); printf("c1=% cc2=% c/n", c1, c2);
}
填空题N个有序整数数列已放在一维数组中,给定的下列程序中,函数fun()的功能是:利用折半查找法查找整数m在数组中的位置。若找到,则返回其下标值;反之,则返回“Not
be found!”。
折半查找法的基本算法是:每次查找前先确定数组中待确定的范围:low和high(low<high),然后把m与中间位置(mid)中元素的值进行比较。如果m的值大于中间位置元素中的值,则下一次的查找范围放在中间位置之后的元素中;反之,下次查找范围落在中间位置之前的元素中,直到low>high,查找结束。
[注意] 部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
[试题源程序] #include <stdio.h>
#define N 10 int fun(int a[],int m)
{ int low=0, high=N-1, mid;
while(low<=high) { mid={{U}} {{U}}
{{/U}} {{/U}}; if(m<a[mid])
high={{U}} {{U}} {{/U}} {{/U}}; eise
if(m>a[mid]) low=mid+1; else
return(mid); } {{U}} {{U}}
{{/U}} {{/U}}(-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"); }
填空题程序测试分为静态分析和动态测试。其中{{U}} 【4】 {{/U}}是指不执行程序,而只是对程序文本进行检查,通过阅读和讨论,分析和发现程序中的错误。
填空题以下程序的功能是:求出数组x中各相邻两个元素的和依次存放到a数组中,然后输出。请填空。
main() { int x[10],a[9],i; for
(i=0;i<10;i++)scanf("%d",&x[i]); for{{U}} {{U}}
12 {{/U}} {{/U}}<10;i++) a[i-1=x[i]+{{U}} {{U}}
13 {{/U}} {{/U}}: for
(i=0;1<9;i++)printf("%d",a[i]); printf("/n");
}
填空题对于长度为n的顺序存储的线性表,当随机插入和删除—个元素时,需平均移动元素的个数为{{U}} 【1】 {{/U}}。
填空题执行以下“for(i=1;i++<=4;i++);”语句后,变量i的值是______。
填空题以下程序运行后的输出结果是 【13】 。
#include
main()
{ int i,n[5]={0};
for(i=1;i<=4;i++)
{ n[i]=n[i-1]*2+1;printf("%d",n[i]); }
printf("\n");
}
