首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
给定程序modil.C的主函数中,将a、b、c三个节点链成一个单向链表,并给各节点的数据域赋值,函数fun()的作用是:累加链表节点数据域中的数据作为函数值返回。 请改正函数fun中指定部位的错误,使它能得出正确的结果。 注意:不要改动main函数
给定程序modil.C的主函数中,将a、b、c三个节点链成一个单向链表,并给各节点的数据域赋值,函数fun()的作用是:累加链表节点数据域中的数据作为函数值返回。 请改正函数fun中指定部位的错误,使它能得出正确的结果。 注意:不要改动main函数
admin
2016-04-07
26
问题
给定程序modil.C的主函数中,将a、b、c三个节点链成一个单向链表,并给各节点的数据域赋值,函数fun()的作用是:累加链表节点数据域中的数据作为函数值返回。
请改正函数fun中指定部位的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include
typedef struct list
{int data;
struct list*next;
}LIST;
int fun(LIST*h)
{LIST*p;
/**********found**********/
int t;
p=h;
/**********found**********/
while(*p)
{
/**********found**********/
t=t+p.data;
p=(*p).next;
}
return t;
}
main()
{UsT a,b,c,*c h;
a.data=34;b.data=51;c.data=87;c.next=\0;
h=&a;a.next=&b;b.next=&c;
printf("总和=%d\n",fun(h));
}
选项
答案
(1)int t;改为int t=0; (2)将while(*p)中的*p改为p或者p!=NULL (3)p.data改为p一>data
解析
(1)int t;改为int t=0;题目中变量t是用来存放累加和的,必须初始化。
(2)*p改为p或者p!=NULL,题目中木p是结构体,不能转化为bool型。
(3)p.data改为p一>data,p是指针,只能用p—>,不能用p.。
转载请注明原文地址:https://jikaoti.com/ti/Ndi0FFFM
本试题收录于:
二级C语言题库NCRE全国计算机二级分类
0
二级C语言
NCRE全国计算机二级
相关试题推荐
下列程序的执行结果是______。#lnClude<stdio.h>unionun{inti;charc[2];};voidmain()
有以下程序:inta=3;main(){ints=0;{inta=5;s+=a++;}s+=a++;printf("%d\n",s);}程序运行后的输出结果是______。
下列程序的输出结果是()。#include<stdio.h>main(){structst{inty,x,z;};
算法的时间复杂度是指______。
设变量已正确定义为整型,则表达式n=i=2,++i,i++的值为【】。
注释说明了程序的功能,它分为【】注释和功能性注释。
下列叙述中,正确的是______。
简单的交换排序方法是()。
算法的空间复杂度是指()。
用筛选法可得到2~n(n
随机试题
挖槽狭窄、挖槽边缘水深小于挖泥船吃水时链斗船宜采用()施工。
定势表现在不同的方面,假如快速给你呈现一幅缺一只脚的狗的图片,你往往会把它看成是完整的狗。这体现的是()。
胆总管与胰管共同开口在()
巨幼细胞贫血时,红细胞直方图的变化为
关于汉坦病毒的免疫性,下列描述正确的是
治疗潮热,盗汗,遗精,腰酸者,常应用熟地黄、山萸肉等,亦可选用
团队建设的有效措施包括()
ThephraseI’dliketoinvolves______phenomenon.
清代是紫砂壶发展的鼎盛时期,制壶名家辈出,在选料、配色、造型、烧制、题材、纹饰、工艺等方面都较完善。紫砂壶的发展与当时的社会经济文化生活息息相关,清代的饮茶习俗非常普及,已成为人民日常生活中的必需品,故紫砂壶的发展日益兴盛。清代的茶有红茶、绿茶、白茶、黄茶
背景:()是《人间喜剧》里的一部长篇小说。
最新回复
(
0
)