C语言 7.docx
《C语言 7.docx》由会员分享,可在线阅读,更多相关《C语言 7.docx(21页珍藏版)》请在冰点文库上搜索。
C语言7
19.以下程序的功能是:
建立一个带有头结点的单向链表,并将存储在数组中的字符依次转储到链表的各个结点中,请为下划线处有号码的选择出正确的选项。
#include
stuctnode
{chardata;structnode*next;};
___(48)___CreatList(char*s)
{structnode*h,*p,*q;
h=(structnode*)malloc(sizeof(structnode));
p=q=h;
while(*s!
='\0')
{p=(structnode*)malloc(sizeof(structnode));
p->data=______;
q->next=p;
q=______;
s++;
}
p->next='\0';
returnh;
}
main()
{charstr[]="linklist";
structnode*head;
head=CreatList(str);
...
23.。
若a、b、c1、c2、x、y均是整型变量,正确的switch语句是______。
①
switch(a+b);
{case1:
y=a+b;break;
case0:
y=a-b;break;
}
②
switch(a*a+b*b)
{case3:
case1:
y=a+b;break;
case3:
y=b-a;break;
}
③
switcha
{casec1:
y=a-b;break;
casec2:
x=a*b;break;
default:
x=a+b;
}
④
switch(a-b)
{default:
y=a*b;break;
case3:
case4:
x=a+b;break;
case10:
case11:
y=a-b;break;
32.。
下面rotate函数的功能是:
将n行n列的矩阵A转置为A',例如:
|1234|
|5678|
当A=|9101112|
|13141516|
|15913|
|261014|
则A'=|371115|
|481216|
请填空。
#defineN4
voidrotate(inta[][])
{inti,j,t;
for(i=0;ifor(j=0;______;j++)
{t=a[i][j];
______;
a[j][i]=t;
}
}