填空题下列给定程序中,函数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;
ho(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);}
填空题以下程序段的输出结果是( )。
#include
mian()
{ char a,b;
for(a=0;a<20;a+=7) { b=a ; putchar(b+’0’); }
}
填空题以下程序运行后,若输入:3,abcde <回车>,则输出结果是 【11】 。 #include <stdio.h> #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]; int n,i,z; scanf("%d,%s", z=strlen(s); for(i=1;i<=n;i++) move(s,z); printf("%s/n",s);
填空题以下程序的输出结果是{{U}} 【18】 {{/U}}。
#define MCRA(m) 2*m
#define MCRB(n,m) 2*MCRA(n)+m
main( )
{ int i=2,j=3;
printf("%d/n",MCRB(j,MCRA(i)));
}
填空题以下程序中给指针p分配3个double型动态内存单元,请填空。 # include <stdio.h> main () double *p; p=(double *)malloc(( 【18】 ); p[0]=1.5;p[1]=2.5;p[2]=3.5; printf("%f%f%f/n",p[0],p[1],p[2]);
填空题请补充函数fun(char *s),该函数的功能是把字符串中的内容逆置。
例如:字符串中原有的字符串为abcde,则调用该函数后,串中的内容变为edcba。
注意;部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
$include<string.h>
#include<conio.h>
#include<stdio.h>
#define N 81
void fun(char*s)
{
int i=0,t,n=strlen(s);
for(;{{U}} 【1】 {{/U}};i++)
{
t=*(s+i);
{{U}}【2】 {{/U}};
{{U}}【3】 {{/U}};
}
}
main()
{
char a[N];
clrscr();
printf("Enter a string:");
gets(a);
printf("The original string is:");
puts(a);
fun(a);
printf("/n");
printf("The string after modified:");
puts(a);
}
填空题以下函数rotate的功能是:将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]={{U}} {{/U}};{{U}} {{/U}}:a[N-1][i];
填空题语句“int(*ptr)();”的含义是______是指向函数的指针,该函数返回一个int型数据。
填空题以下程序运行后的输出结果是______。
#include<stdio.h>
int main()
{
int n=0, m=-10, x=2;
if(!n)x-=1;
if(-m)x-=2;
if(x)x-=3;
printf("%d/n", x);
return 0;
}
填空题执行下列语句段后,x的值是______。 int*p,X; x=100; p= x=*p+50;
填空题下列程序中,fun( )函数的功能是计算x2-2x+6,主函数中将调用fun( )函数计算。 y1=(x+8)2-2(x+8)+6 y2=sin2(x)-2sin(x)+6 请填空 #include "math.h" double fun(double x)return(x*x-2*x+6);) main() double x,y1,y2; printf("enter x:");scanf("%1f",&x); y1=fun(______); y2=fun(______); printf("y1=%1f,y2=%1f/n",y1,y2);
填空题C语言程序的注释可以出现在程序中的任何地方,一个注释以 【11】 分别作为开始和结束。
填空题结构变量的长度等于所有成员长度之和,而联合变量的长度等于______。
填空题以下程序运行后的输出结果是______。 main ( ) char m; m = 'B' + 32; printf ("%e/n" ,m);
填空题以下函数的功能是计算,请填空。doublefun(intn) doubles=0.0,fac=1.0;inti; for(i=1;i<=n;i++) fac=fac______; s=s+fac; returns;
填空题测试的目的是暴露错误,评价程序的可靠性;而______得目的是发现错误的位置并改正错误。
填空题下面的程序可对指定字符串进行从大到小排序,请将程序填完整。 (注:程序采用了冒泡排序算法)
#include<stdio.h>
#include<string.h>
main()
{ char*str="ABCDabcd",temp;
int n,i;
n=strlen(str);
while(n->1)
for(i=0;i<n;i++)
if(str[i]<str[i+1])
{ temp={{U}} 【12】 {{/U}};
str[i]=str[i+1];
{{U}}【13】 {{/U}}=temp;
}
printf({{U}} 【14】 {{/U}});
}
填空题以下函数用来求出数组的最大元素在数组中的下标并存放在k所指的存储单元中。请填空。 #include
<conio.h> #include <stdio.h> int fun(int *s,
int t, int *k) {int i; *k=0;
______ if(s[*k]<s[i]) *k=i; return
______;} main() {int
a[10]={876,675,896,101,301,401,980,431,451,777},k;
fun(a,10,}
填空题以下程序的输出结果是 【8】 。 main() int arr[]=30,25,20,15,10,5,*p=arr; p++; printf("%d/n",*(p+3));
填空题若想通过以下输入语句使a=5.0,b=4,c=3,则输入数据的形式应该是{{U}} 【10】 {{/U}}。
int b,c;float a;
scanf("%f,%d,c=%d",&a,&b,&c)
