填空题以下程序运行后输出的结果是{{U}} 【9】 {{/U}}。
main()
{ int x=1,y=0,a=0,b=0;
switch(x)
{ case 1:switch(y)
{
case 0:a++;break;
case 1:b++;break;
}
case 2:a++;b++;break;
}
printf("%d%d/n",a,b) ;
}
填空题给定程序中已建立一个带有头结点的单向链表,在main函数中将多次调用fun函数,每调用一次fun函数,输出链表尾部结点中的数据,并释放该结点,使链表缩短。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
不得增行或删行,也不得更改程序的结构!
给定源程序:
#include<stdio.h>
#include<stdlib.h>
#define N 8
typedef struct list
{int data;
struct list*next;
}SLIST;
void fun(SLIST*p)
{SLIST*t,*s;
t=p->next;s=p;
while(t->next!=NULL)
{s=t;
/**********found**********/
t=t->______;
}
/**********found**********/
printf("%d",______);
s->next=NULL;
/**********found**********/
free(______);
}
SLIST*creatlist(int*a)
{SLIST*h,*p,*q;int i;
h=p=(SLIST*)malloc(sizeof(SLIST));
for(i=0;i<N:i++)
{q=(SLIST*)malloc(sizeof(SLIST));
q->data=a[i];p->next=q;p=q;
}
p->next=0;
return h;
}
void outlist(SLIST*h)
{SLIST*p;
p=h->next;
if(p==NULL)printf("/nThe list is NULL!/n");
else
{printf("/nHead");
do{printf("->%d",p->data);
p=p->next;}while(p!=NULL);
printf("->End/n");
}
}
main()
{SLIST*head;
int a[N]={11,12,15,18,19,22,25,29};
head=creatlist(a);
printf("/nOutput from head:/n");outlist(head);
printf("/nOutput from tail:/n");
while(head->next!=NULL){
fun(head);
printf("/n/n");
printf("/nOutput from head again:/n");
outlist(head);
}
}
填空题下面程序的功能是将方阵m中左下半三角(含对角线)所有元素值增加10,右上半三角所有元素值乘以5的形式重置,并输出重置前及重置后的方阵m。请填空完善程序。
#include<stdio.h>
int main()
{
int m[5][5]={2, 3, 1, 1, 5, 6, 7, 9, 11, 15, 18, 36, 17, 26, 22, 8, 25, 10, 12, 20, 25, 4, 13, 30, 16};
int i, j;
printf("Previous array is:/n");
for(i=0; i<5; i++)
{
for(j=0; j<5; j++)
printf("%3d", m[i][j]);
printf("/n");
}
for(i=0; i<5; i++)
for(j=0; j<5; j++)
{
if(______)
m[i][j]+=10;
else
______;
}
printf("Current array is:/n");
for(i=0; i<5; i++)
{
for(j=0; j<5; j++)
printf("%3d", m[i][j]);
printf("/n");
}
return 0;
}
填空题若有如下程序: #include "stdio.h" main() char s[30]; Strcpy( Strcpy( strcpy(; printf("%S/n",s); 则程序运行后的输出结果是 【7】 。
填空题以下fun函数的功能是:找出具有N个元素的一维数组中的最小值,并作为函数值返回,请填空。(设N已定义)
int fun(int x[N])
{int i,k=0;
for(i=0;i<N;i++)
if(x[i]<x[k])k={{U}} (10) {{/U}};
return x[k];
}
填空题C源程序的基本单位是______。
填空题有以下程序: #include<stdio.h> main() FILE *fp;int i,a[6]=1,2,3,4,5,6; fp=fopen(“d3.dat”,“w+b”); fwrite(a,sizeof(int),6,fp); fseek(fp,sizeoffint)*3,SEEK SET);/*该语句使读文件的位置指针从文件头向后移动3个int型数据*/ fread(a,sizeoflint),3,fp);fclose(fp); for(i=0;i<6;i++printf("%d,",a[i]); 程序运行后的输出结果是______。
填空题由25人围坐成圆圈,先从任意一人出发用1到25顺时针依次编号,然后从1号开始顺时针报数(1、2、3…),凡报5的倍数者出圈,剩下者继续报数,求出最后出圈者的编号。 # include<stdio.h> 【13】 int a[26],j,n,count; for(j=1;j<=25;j + +)a[j]=j; j=1;count=0;n= 【14】 ; do if (a [j]! =0) n + + ; if (n% 5==0) 【15】 ; if (count==24)printf ("%d/n",j); count + + ; j + + ; if (j>25)j=1; while( 【16】 );
填空题若有以下定义,则使指针p指向值为35的数组元素的语句是______。
int a[10]={14,27,47,29,35,21,49,71},*p;
填空题执行以下程序时输入1234567<CR>,则输出结果是{{U}} 【6】 {{/U}}。
#include <stdio.h>
main()
{ int a=1,b;
scanf("%2d%2d", prinff("%d %dhn",a,b);
}
填空题请用位运算实现下述目标(设16位二进制数的最低位为零位):(1)输出无符号正整数m的第i个二进制位的数值。(2)将m的第i个二进制位置1,其余的位不变,然后输出m。#include "stdio.h" 【13】 main() unsigned k,i,m=0; scanf("%d%d",&m,&i); k= 【14】 ; printf("%d/n",k); k=pow(2,i); m= 【15】 ; printf("%d/n",m);
填空题请补充main函数,该函数的功能是:从键盘输入若干字符放到一个字符数组中,当桉回车键时结束输入,最后输出这个字符数组中的所有字符。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在 main函数的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#include<ctype.h>
main()
{
int i=0;
char a [81];
char *p=s;
clrscr ();
printf{" Input a string /n");
for (i=0; i<80; i++)
{
s [i] =getchar ( );
if (s [i]=='/n')
{{U}}【1】{{/U}};
}
s[i]={{U}} 【2】{{/U}}
printf(" display the string /n");
while (*p)
putchar ({{U}}【3】 {{/U}});
}
填空题以下函数将b字符串连接到a字符串的后面,并返回a中新字符串的长度。
strcen(char aC), char b[])
{ int num=0,n=0;
while(*(a+num)!={{U}} 【14】 {{/U}}) num++;
while(b[n]){*(a+num)=b[n]; num++;{{U}} 【15】 {{/U}};)
return(num);
}
填空题若有定义int a=10,b=9,c=8;,接着顺序执行下列语句,变量b中的值是 【6】 。 c=(a-=(b-5)); c=(a%11)+(b=3);
填空题给定程序中,函数fun的功能是:计算x所指数组中N个数的平均值(规定所有数均为正数),平均值通过形参返回主函数,将小于平均值且最接近平均值的数作为函数值返回,在主函数中输出。
例如,有10个正数:46 30 32 40 6 17 45 15 48 26,平均值为:30.500000。主函数中输出:m=30。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
不得增行或删行,也不得更改程序的结构!
给定源程序:
#include<stdlib.h>
#include<stdio.h>
#define N 10
doubte fun(double x[], double *av)
{ int i, j; double d, s;
s=0;
for(i=0; i<N; i++)s=s+x[i];
/**********found**********/
______=s/N;
d=32767;
for(i=0; i<N; i++)
if(x[i]<*av j=______;}
/**********found**********/
return______;
}
main()
{ int i;
double x[N]={46, 30, 32, 40, 6, 17, 45, 15, 48, 26};
double av, m;
for(i=0; i<N; i++)printf("%4.0f", x[i]);
printf("/n");
m=fun(x,
printf("/nThe average is:%f/n", av);
printf("m=%5.0f", m);
printf("/n");
}
填空题若a=1,b=2,则表达式!(x=A)‖y=B) &&0的值是______。
填空题以下程序运行后的输出结果是 【16】 。 #include <stdio, h>#include <stating, h>void fun(char * s,int p,int k) int i; for(i=p;i<k-1;i++) s[i] =s[i+2];main( ) char s [] = "abedefg"; fun(s,3 ,strlen(s) ); puts(s);
填空题以下程序中给指针p分配3个double型动态内存单元,请填空。
# include <stdio.h>
main ()
{ double *p;
p=(double *)malloc(({{U}} 【18】 {{/U}});
p[0]=1.5;p[1]=2.5;p[2]=3.5;
printf("%f%f%f/n",p[0],p[1],p[2]);
}
填空题以下程序的功能是;求出数组X中各相邻两个元素的和依次存放到a数组中,然后输出。请填空。
main()
{int x[10],a[9],i;
for(i=O;i<10;i++)scanf("%d",
for(i=O;i<9;i++)printf("%d",a[i]);
printf("");
}
填空题下列程序的输出结果是{{U}} 【6】 {{/U}}。
#define PR(a)printf("%d/t",(int)(a))
#define PRINT(a)PR(a);printf("ok!")
main()
{ int i,a=1;
for(i=0;i<3;i++)
PRINT(a+i);
printf("/n");}