填空题以下程序中函数fun的功能是:构成一个如图所示的带头节点的单向链表,在节点的数据域中放入了具有两个字符的字符串。函数disp的功能是显示输出该单链表中所有节点中的字符串。请填空完成函数disp。#include<stdio.h>typedefstructnode/*链表节点结构*/charsub[3];structnode*next;Node;Nodefun(chars)/*建立链表*/…voiddisp(Node*h)Node*p;p=h->next;while______printf("%s/n",p->sub);p=p->next;main()Node*hd;hd=fun();disp(hd);printf("/n");
填空题给定程序中,函数fun的功能是计算形参x所指数组中N个数的平均值(规定所有数均为正数),将所指数组中小于平均值的数据移至数组的前部,大于等于平均值的数据移至x所指数组的后部,平均值作为函数值返回,在主函数中输出平均值和移动后的数据。
例如,有10个正数:46 30 32 40 6 17 45 15 48 26,平均值为30.500000。
移动后的输出为30 6 17 15 26 46 32 40 45 48
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
给定源程序如下。
#include<stdlib.h>
#include<stdio.h>
#define N 10
double fun(double*x)
{ int i,j;double av,y[N];
av=0;
/***********found***************/
for(i=0;i<N;i++)av+=______;
for(i=j=0;i<N;i++)
if(x[i]<av){
/***********found*************/
y[j]=x[i];x[i]=-1;______;}
i=0;
while(i<N)
{ if(x[i]!=-1)y[j++]=x[i];
/**********found*******/
______;
}
for(i=0;i<N;i++)x[i]=y[i];
return av;
}
main()
{ int i;double x[N];
for(i=0;i<N;i++){ x[i]=rand()%50;
printf("%4.0f",x[i]);}
printf("/n");
printf("/nThe average is:%f/n",fun(x));
printf("/nThe result:/n",fun(x));
for(i=0;i<N;i++)printf("%5.0f",x[i]);
printf("/n");
}
填空题以下函数用来求出两整数之和,并通过形参将结果传回,请填空。
void func(int x,int y,{{U}} 【13】 {{/U}}z)
{ *z=x+y; }
填空题下面程序的运行结果是:【 】
int f( int a[ ], int n)
{ if(n>1) return a[0]+f(
else return a[0];}
main ( )
{ int aa[3]={1,2,3},s;
s=f( ; printf(“%d/n”,s);}
填空题设有定义:
int n, * k=
以下语句将利用指针变量k读写变量n中的内容,请将语句补充完整。
scanf("% d", ______);
printf("% d/n", ______);
填空题下列给定程序中,函数fun()的功能是:将m(1≤m≤10)个字符串反着连接起来,组成一个新串,放入pt所指字符串中,例如:把3个串DEG,ac,df反着串联起来,结果是dfacDEG。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动main()函数,不得增行或者删行,也不得改变程序的结构! 试题程序: #include <conio.h> #include <string.h> #include <stdio.h> void fun(char str[][10],int m,char *pt) int k,q,i,j=0; /*************found*************/ for(k=m;k>0;k--) q=strlen(str[k]); j+=q; for(i=0;i<q;i++) pt[i]=str[k][i]; pt+=q; pt[0]=0; /*************found**************/ pt=j; main() int m,h; char s[10][10],p[120]; clrscr(); printf("/nPlease enter m:"); scanf("%d",& m); printf("/nPlease enter%d string:/n",m); gets(s[0]); for(h=0;h<m;h++) gets(s[h]); fun(s,m,p); printf("/nThe result is:%s/n",p);
填空题给定程序中,函数fun的功能是:将形参s所指字符串中的所有数字字符顺序前移,其他字符顺序后移,处理后新字符串的首地址作为函数值返回。
例如,s所指字符串为:asd123fgh543df,处理后新字符串为:123543asdfghdf。请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。
注意:不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
char*fun(char*s)
{int i,j,k,n;char *p,*t;
n=strlen(s)+1;
t=(char*)malloc(n*sizeof(char));
p=(char*)malloc(n*sizeof(char));
j=0;k=0;
for(i=0;i<n;i++)
{if(isdigit(s[i])){
/*********found*********/
p[______]=s[i];j++;}
else
{t[k]=s[i];k++;}
}
/*********found*********/
for(i=0;i
p[j+i]=t[i]; p[j+k]=0; /*********found*********/ return ______; } main() {char s[80]; printf("Please input:"); scanf("%s",s); printf("/nThe result is:%s/n",fun(s)); } (1)j (2)k (3)p或(p)[解析] 填空1:函数中申请了两个内存空间,其中p存放数字字符串,t存放非数字字符串,根据条件可知,p依次存放数字字符串,其位置由j来控制,所以应填j。 填空2:利用for循环再把t中的内容依次追加到p中,其中t的长度为k,所以应填k。 填空3:处理之后的字符串存放到p中,最后返回p的首地址即可,所以应填p。
填空题数据结构包括数据的逻辑结构、数据的 【2】 以及列数据的操作运算。
填空题若整型变量a和b中的值分别为7和9,要求按以下格式输出a和b的值: a=7 b=9 请完成输出语句: printf("______",a,b);
填空题在C语言中,可以利用 【6】 ,将一个表达式的值转换成指定的类型。
填空题有以下语句段
int n1=10,n2=20; printf(“ {{U}} 【7】 {{/U}} ”,n1.n2);
要求按以下格式输出n1和n2的值,每个输出行从第一列开始,请填空。
n1=10 n2=20
填空题下列给定程序中,函数proc()的功能是找出100~m(m不大于1000)之间百位数字加十位数字等于个位数字的所有整数,把这些整数放在s所指的数组中,个数作为函数值返回。 请修改程序中的错误,使它能得到正确结果。 注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #include<stdio.h> #define M 1000 int proc(int *s, int n) int i, j, k, a, b, c; j=0; for(i=100; i<n; i++) //************found************* k=n; a=k%10; k/=10; b=k%10; c=k/10; if(a==b+c) //************found************* s[j]=i; return j; void main() int a[M], m, num=0, i; do printf("/nEnter m(<=1000): "); scanf("%d", while(m>1000); num=proc(a, m); printf("/n/nThe result: /n"); for(i=0; i<num; i++) printf("%5d", a[i]); printf("/n/n");
填空题以下程序运行后的输出结果是 【12】 。 main() char a[]="123456789",*p; int i=0; p=a; while(*p) if(i%2==0) *p='*'; p++;i++; puts(A) ;
填空题以下程序运行后的输出结果是【 】。
main( )
{ int i,m=0,n=0,k=0;
for(i=9; i<=11;i++)
switch(i/10)
{ case 0: m++;n++;break;
case 10: n++; break;
default: k++;n++;
}
printf("%d %d %d/n",m,n,k);
}
填空题在E-R图中,______表示实体间的联系。
填空题以下程序的输出结果是 【17】 。 void fun() static int a; a+=2; printf("%d",a); main() int cc; for(cc=1;cc<=4;cc++)fun(); printf("/n");
填空题下列给定程序中,函数fun的功能是:统计带头结点的单向链表中结点的个数,并存放在形参n所指的存储单元中。
请在下划线处填入正确的内容并将下划线删除,使程序得出正确的结果。
注意
:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include <stdio.h>
#include <stdlib.h>
#define N 8
typedef struct list
{int data;
struct list *next;
}SLIST;
SLIST*creatlist(int *a);
void outlist(SLIST *);
void fun(SLIST *h, int *n)
{SLIST *p;
/********found********/
______=0;
p=h->next;
while(p)
{(*n)++;
/********found********/
p=p->______;
}
}
main()
{SLIST *head;
int a[N]={12,87,45,32,91,16,20,48}, num;
head=creatlist(a);
outlist(head);
/********found********/
fun(______,
printf("/nnumber=%d/n",num);
}
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("The list is NULL!/n");
else
{printf("/nHead");
do
{printf("-%d",p->data);
p=p->next;}
while(p!=NULL);
prinft("->End/n");
}
}
填空题下列给定的程序中,函数fun()的功能是:判断字符ch是否与str所指字符串中的某个字符相同;若相同,则什么也不做,若相同,则将其插在申的最后。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <conio.h>
#include <stdio.h>
#include <string.h>
/*************found**************/
void fun (char str,char ch)
{while (*str
/*************found**************/
if(*str==ch)
{ str[0]=ch;
/*************found**************/
str[1]='0';
}
}
main()
{char s[81],c;
clrscr();
printf("/nPlease enter a strzng : ");
gets(s);
printf("/n Please enter the character to
search : ");
c=getchar();
fun(s,c);
printf("/nThe result is %s/n",s);
}
填空题以下程序的功能是调用函数fun计算:m=1-2+3-4+…+9-10,并输出结果。请填空。
int fun( int n)
{ int m=0,f=1,i;
for(i=1; i<=n; i++)
{ m+=i*f;
f={{U}} 【11】 {{/U}};
}
return m;
}
main( )
{ printf("m=%d/n",{{U}} 【12】 {{/U}} ); }
填空题以下程序的功能是建立一个带有头结点的单向链表,链表结点中的数据通过键盘输入,当输入数据为-1时,表示输入结束(链表头结点的data域不放数据,表空的条件是ph->next==NULL),请填空。 #include <stdio.h> struct list int data;struct list *next;; struct list *creatlist( ) struct list *p,*q,*ph;int a;ph=(struct list*)malloc(sizeof(struct list)); p=q=ph;printf("Input an integer number;entre-1 to end:/n"); scanf("%d",&a); while(a!=-1) p=(struct list*)malloc(sizeof(struct list)); [14] =a;q->next=p; [15] =p;scanf("%d",&a); p->next='/0';return(ph); main( ) stuct list * head;head=creatlist();
