首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
给定程序modil.c的主函数中,将a、b、c三个结点链成一个单向链表,并给各结点的数据域赋值,函数fun()的作用是:累加链表结点数据域中的数据作为函数值返回。 请改正函数fun中指定部位的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增
给定程序modil.c的主函数中,将a、b、c三个结点链成一个单向链表,并给各结点的数据域赋值,函数fun()的作用是:累加链表结点数据域中的数据作为函数值返回。 请改正函数fun中指定部位的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增
admin
2020-11-27
23
问题
给定程序modil.c的主函数中,将a、b、c三个结点链成一个单向链表,并给各结点的数据域赋值,函数fun()的作用是:累加链表结点数据域中的数据作为函数值返回。
请改正函数fun中指定部位的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<stdio.h>
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()
{LIST a,b,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)*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://kaotiyun.com/show/Qstp777K
本试题收录于:
二级C语言题库NCRE全国计算机二级分类
0
二级C语言
NCRE全国计算机二级
相关试题推荐
设有定义chars=[81],Int1=0,以下不能将一行(不超过80个字符)带自空格的字符串正确读入的语句或语句组是()。
有以下程序:#include#includevoidfun(int:**s,intx[2][3]){**s=*(x[1]+1);}voidmain(){inta[2][3]={1,2,3,4,5,6
有以下程序,程序中库函数islower(ch)用以判断ch中的字母是否为小写字母#include#includevoidfun(char*p){inti=0;while(p[i]){if(p
有三个关系R、S和T如下:由关系R和S通过运算得到关系T,则所使用的运算为
以卜叙述中正确的是
以下叙述中错误的是()。
下列选项中正确的标识符是()。
一棵二叉树中共有70个叶子结点与80个度为1的结点,则该二叉树中的总结点数为
下列各项中,不属于软件设计阶段任务的是()。
随机试题
就这个方法本身而言,它值得一试。
下列关于吸附法的叙述,说法错误的是()。
风险识别工作不包括()。
甲企业(增值税一般纳税人)为某市一家酒厂,生产各种酒类产品。2014年2月,甲企业发生下列经营业务:(1)向乙企业销售白酒80吨,取得不含税销售收入400万元,另单独收取包装费37万元。向个人零售白酒5吨,取得销售额11.7万元。(2)
教师的“楷模"“榜样”“引路人”的角色,都充分说明了教师的劳动具有()
近年来,国家财政把支持解决“三农”问题放在财政工作的首要位置,从()城乡发展的战略高度出发,不断加大投入力度,目前已经初步()财政支持“三农”资金稳定增长机制。
2015年全年全国粮食总产量62143万吨,增长2.4%。谷物产量57225万吨,比上年增长2.7%。棉花产量560.5万吨,比上年下降9.3%。全年猪牛羊禽肉产量8454万吨,比上年下降1.0%,其中猪肉产量5487万吨,下降3.3%,而上年同期为增长3
火:热情:态度
农业示范基地
若f(x)=在x=0处连续,则a=______.
最新回复
(
0
)