填空题给定程序中,函数fun的功能是将带头结点的单向链表结点数据域中的数据从小到大排序。即若原链表结点数据域从头至尾的数据为:10、4、2、8、6,排序后链表结点数据域从头至尾的数据为:2、4、6、8、10。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
不得增行或删行,也不得更改程序的结构!
给定源程序:
#include<stdio.h>
#include<stdlib.h>
#define N 6
typedef struct node{
int data;
struct node *next;
}NODE;
void fun(NODE *h)
{NODE *p,*q;int t;
/**********found**********/
p=______;
while(p){
/**********found**********/
q=______;
while(q){
/**********found**********/
if (p->data______q->data)
{t=p->data;p->data=q->data;q->data=t;}
q=q->next;
}
p=p->next;
}
}
NODE*creatlist(int a[])
{NODE*h,*p,*q;int i;
h=(NODE*)malloc(sizeof(NODE));
h->next=NULL;
for(i=0;i<N;i++)
{q=(NODE*)malloc(sizeof(NODE));
q->data=a[i];
q->next=NULL;
if (h->next==NULL)h->next=p=q;
else{p->next=q;p=q;}
}
return h;
}
void outlist(NODE*h)
{NODE*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);
printf("->End/n");
}
}
main()
{NODE*head;
int a[N]={0,10,4,2,8,6};
head=creatlist(a);
printf("/nThe original list:/n");
outlist(head);
fun(head);
printf("/nThe list after sorting:/n");
outlist(head);
}
填空题下列给定程序中,函数fun()的功能是:从形参ss所指字符串数组中,删除所有串长超过k的字符串,函数返回剩余字符串的个数。SS所指字符串数组中共有N个字符串,且串长小于M。
请在标号处填入正确的内容,使程序得出正确的结果。 注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构。
试题程序 #include
<stdio.h> #include <string.h> #define N
5 #define M 10 int fun(char (* ss)[M], int
k) { int i, j=0, len; for(i=0; i<______;
i++) { len=strlen (ss[i];
if(len<=______) strcpy(ss[j++], ______);
} return j; }
main() { char x[N][M]={"Beijing", "Shanghai", "Tianjin",
"Nanjing", "Wuhan"}; int i, f; printf("/nThe
original string/n/n"); for(i=0; i<N; i++)puts(x[i]);
printf("/n"); f=fun(x, 7); printf("The
string witch length is less than or equal to 7:/n"); for(i=0;
i<f; i++) puts(x[i]); printf("/n"); }
填空题以下程序的功能是将宁符串s中的数字字符放入d数组中,最后输出d中的字符串。例如,输入字符串:abcl23edf4568h,执行程序后输出:123456。请填空。 #include <stdio.h> #include <ctype.h> main() char s[80],d[80]; int i,j; gets(s); for(i=j=0;s[i]!='/0';i++) if( 【20】 ) d[j]=s[i];j++; d[j]='/0'; puts(d);
填空题以下程序的功能是从键盘上输入一行字符,存入一个字符数组中,然后输出该字符串。请填空。 main() char str[81],*sptr; int i; for(i=0;i<80;i++) str[i]=getchar(); if(str[i]=='/n')break; str[i]= 【10】 ; sptr=str1 while(* sptr)putchar(* sptr 【11】 );
填空题阅读下面程序,则执行后的输出结果是______。 #include"stdio.h" main() int x, y, 2; x=1; y=2; z=3; if(x>y)if(x>z)printf("%d", x); else printf("%d", y); printf("%d/n",z);
填空题已知字符'A'的ASCII代码值为65,以下程序运行时若从键盘输入:B33 <回车>,则输出结果是 【9】 。 #include <stdio.h> main( ) char a,b; a = getchar( ) ;seanf( "% d" , a=a-'A' +'0';b=b* 2; prinff( "% c % c /n" ,a,b);
填空题下列程序的运行结果是______。
#define P(A) printf("%d",A)
main()
{ int j,a[]={1,2,3,4,5,6,7},i=5;
for(j=3;j>1;j--)
{ switch(j)
{ case 1:
case2:P(a[i++]);break;
case 3:P(a[--i]);
}
}
}
填空题以下程序运行后的输出结果是______。
#include<stdio.h>
int main()
{
struct time
{
int h;
int m;
int s;
};
struct time*p, audit={8, 30, 0};
p=
printf("/naudition time is %2d:%2d:%2d", p->h, p->m, p->s);
return 0;
}
填空题有以下程序 #include <stdio.h> int a=5; void fun(int b) int a=10; a+=b;printf("%d",a); main() int c=20; fun(c);a+=c;printf("%d/n",a); 程序运行后的输出结果是______。
填空题以下程序运行后的输出结果是______。 main() int m=011,n=11; printf("%d%d/ff",++m,n++);
填空题以下程序段打开文件后,先利用fseek函数将文件位置指针定位在文件末尾,然后调用 ftell函数返回当前文件位置指针的具体位置,从而确定文件长度。请填空。 FILE * myf;long f1; myf= 【20】 ("test.t","rb"); fseek(myf,0,SEEK END) ; f1=ftell(myf); fclose(myf); printf("%d/n",f1);
填空题下面的语句定义了结构类型stu,并说明了结构变量person:
struct stu
{
int num;
char name[20];
}person;
若要定义stu的别名PERSON,其正确的定义形式为:______。
填空题下述程序在数组中同时查找最大元素下标和最小元素下标,分别存放在main()函数的变量max和min中,请填空。
试题程序 #include
<stdio.h> void find(int*a, int n, int*max, int*min)
{ int i; *max=*min=0; for(i=1; i<n;
i++) if(a[i]>a[*max]) ______;
else if(a[i]<a[*min]) ______;
} main() { int a[]={5,8,7,6,2,7,3};
int max, min; find(_______);
printf("/n% d, % d", max, min); }
填空题以下程序段打开文件后,先利用fseek函数将文件位置指针定位在文件末尾,然后调用ftell函数返回当前文件位置指针的具体位置,从而确定文件长度,请填空。 FILE*myf; long f1; myf=______("test,t","rb"); fseek(myf,(),SEEK_END) ;f1+ftell(myf); fclose(myf); printf("%1d/n",f1);
填空题下列给定程序中,函数fun的功能是:在形参ss所指字符串数组中查找与形参t所指字符串相同的串,找到后返回该串在字符串数组中的位置(即下标值),若未找到则返回-1。ss所指字符串数组中共有N个内容不同的字符串,且串长小于M。 请在下划线处填入正确的内容并将下划线删除,使程序得出正确的结果。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的结构! 试题程序: #include <stdio.h> #include <string.h> #define N 5 #define M 8 int fun(char (*ss)[M], char *t) int i; /******************found*******************/ for(i=0; i<______; i++) /******************found*******************/ if(strcmp(ss[i], t)==0) return______; return(-1); main() char ch[N][M]("if", "while", "switch", "int", "for", t[M]; int n, i; printf("/nThe original string/n/n"); for(i=0; i<N; i++)puts(ch[i]); printf("/n"); printf("/nEnter a string for search:"); gets(t); n=fun(ch, t); /******************found*******************/ if(n==______) printf("/nDon't found!/n"); else printf("/nThe position is %d./n", n);
填空题在一棵二叉树上第6层的结点个数最多是______。
填空题以下程序运行后输入:3,abcde<回车>,则输出结果是 【13】 。 # include<string.h> move(char *str,int n) char temp int i; temp=str[n-1); for(i=n-1;i>0;i--)str[i]=str[i-1]; str[0]=temp main() char s[50];iht n,i,z; scanf("%d,%s", z=strlen(s); for(i=1;i<=n;i++)move(s,z); printf("%s/n",s);
填空题结构化分析方法是面向______进行分析的方法。
填空题以下程序给指针p分配三个double型动态内存单元,请填空。 #include <stdio.h> #include <stdlib.h> main() double *p; p=(double *)malloc( 【7】 ); p[0]=1.5;p[1]=2.5;P[2]=3.5; printf("%f%f%f/n",p[0],p[1],p[2]);
填空题有以下程序 main() int x=1,y=1,z=1; y=y+z;x=x+y; printf("%d",x<y?y:x); printf("%d",x<y?x++:y++); printf("%d",x); printf("%d",y); 运行结果是 【6】
