C考试系统题库含答案程序题

内容发布更新时间 : 2025/6/15 6:49:03星期一 下面是文章的全部内容请认真阅读。

}

main ( )

{static struct complx za = {3,4}; static struct copmlx zb = {5,6}; struct complx z, x, y; z=cmult(); cpr (za, zb, z); }

F3以下程序的输出结果为“4,2”,请将程序补充完整。 #include main()

{enum color {Red, White=<3>, Blue, Green=1, Yellow}; enum color p;

=&c1; c1=Blue; c2=Yellow;

printf(\}

F4 以下程序中,main函数调用add函数能求出单向链表中所有节点数据域的和并存放在sum中。请将程序补充完整。 #include \struct link {int data; stuct link *next; };

int add(struct link *head) {struct link *p; int s=0; p=; while(p)

{s+=; p=p++; }

return(s); }

main ( )

{struct link *head; ...... /* 创建链表的程序段,省略 */ sum=; printf(\ }

N5 以下output函数输出链表上数据大于n的所有节点。请将函数补充完整。 #include struct Ai {

21

int a;

struct Ai *next; };

void output(struct Ai *head) {int i=0; struct Ai *p;

if(head==NULL)

{printf(\} else

{ p=; do {i++;

if(p.a大于n)

printf(\指向) p=p指向next;

}while(p.next!=NULL); } }

F6 下面函数delete的功能是,删除单向链表中数据值为num的第一个节点。请将程序补充完整。 #include \struct Ai {int a;

struct Ai *next; };

< struct Ai > *delete (struct Ai *head) {struct Ai *p1, *p2; if(head==NULL)

{printf(\ return(head); }

p1=head;

while(p1.next!=NULL) {p2=p1;

p1=p1指向; }

if(num==p1指向) {if(p1==head)

head==NULL; else p2=p1; free(p1);

printf(\}

22

else

printf(\return(head); } </

>>灞曞紑鍏ㄦ枃<<
12@gma联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4 ceshi