档案网站建设比较分析,大连开发区二手房,学习网站建设的网站,通辽市北京网站建设第54套#xff1a;
给定程序中#xff0c;函数fun的功能是:计算出带有头结点的单向链表中各结点数据域中值之和作为函数值返回。 请在程序的下划线处填入正确的内容并把下划线删除#xff0c;使程序得出正确的结果。 注意#xff1a;源程序存放在考生文件夹下的BLANK1.C中…第54套
给定程序中函数fun的功能是:计算出带有头结点的单向链表中各结点数据域中值之和作为函数值返回。 请在程序的下划线处填入正确的内容并把下划线删除使程序得出正确的结果。 注意源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行也不得更改程序的结构 给定源程序
#include stdio.h
#include stdlib.h
#define N 8
typedef struct list
{ int data;
struct list *next;
} SLIST;
SLIST *creatlist(int *);
void outlist(SLIST *);
int fun( SLIST *h)
{ SLIST *p; int s0;
ph-next;
while(p)
{
s p-___1___;
pp-___2___;
}
return s;
}
main()
{ SLIST *head;
int a[N]{12,87,45,32,91,16,20,48};
headcreatlist(a); outlist(head);
/
printf(\nsum%d\n, fun(___3___));
}
SLIST *creatlist(int a[])
{ SLIST *h,*p,*q; int i;
hp(SLIST *)malloc(sizeof(SLIST));
for(i0; iN; i)
{ q(SLIST *)malloc(sizeof(SLIST));
q-dataa[i]; p-nextq; pq;
}
p-next0;
return h;
}
void outlist(SLIST *h)
{ SLIST *p;
ph-next;
if (pNULL) printf(The list is NULL!\n);
else
{ printf(\nHead );
do
{ printf(-%d, p-data); pp-next; }
while(p!NULL);
printf(-End\n);
}
} 解题思路 本题是计算出带有头结点的单向链表中各结点数据域中值之和。 第一处累加数据域中的值所以应填data。 第二处指定p的下一个指针所以应填next。 第三处函数调用在主函数中已经给出了head所以应填head。 给定程序MODI1.C中函数fun的功能是:将s所指字符串中出现的与t1所指字符串相同的子串全部替换成t2所指字符串,所形成的新串放在w所指的数组中。在此处要求t1和t2所指字符串的长度相同。例如当s所指字符串中的内容为“abcdabfab”t1所指子串中的内容为“ab”t2所指子串中的内容为99时 结果在w所指的数组中的内容应为 “99cd99f99”。 请改正程序中的错误使它能得出正确的结果。 注意不要改动main函数不得增行或删行也不得更改程序的结构 给定源程序
#include stdio.h
#include string.h
int fun (char *s, char *t1, char *t2 , char *w)
{
int i; char *p , *r, *a;
strcpy( w, s );
while ( *w )
{ p w; r t1;
while ( r )
if ( *r *p ) { r; p; }
else break;
if ( *r \0 )
{ a w; r t2;
while ( *r ){
*a *r; a; r
}
w strlen(t2) ;
}
else w;
}
}
main()
{
char s[100], t1[100], t2[100], w[100];
printf(\nPlease enter string S:); scanf(%s, s);
printf(\nPlease enter substring t1:); scanf(%s, t1);
printf(\nPlease enter substring t2:); scanf(%s, t2);
if ( strlen(t1)strlen(t2) ) {
fun( s, t1, t2, w);
printf(\nThe result is : %s\n, w);
}
else printf(Error : strlen(t1) ! strlen(t2)\n);
} 解题思路 第一处判断字符串当前字符是否是字符串结束符所以应改为while(*r)。 第二处语句后缺少分号。 函数fun的功能是将s所指字符串中下标为偶数的字符删除串中剩余字符形成的新串放在t所指数组中。 例如当s所指字符串中的内容为“ABCDEFGHIJK” 在t所指数组中的内容应是“BDFHJ”。 注意: 部分源程序存在文件PROG1.C中。 请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入 你编写的若干语句。 给定源程序
#include stdio.h
#include string.h
void fun(char *s, char t[])
{
}
main()
{
char s[100], t[100];
printf(\nPlease enter string S:); scanf(%s, s);
fun(s, t);
printf(\nThe result is: %s\n, t);
NONO();
} 解题思路 本题是从一个字符串按要求生成另一个新的字符串。我们使用for循环语句来解决这个问题。 参考答案
void fun(char *s, char t[])
{
int i, j 0 ;
for(i 1 ; i strlen(s); i2) t[j] s[i] ;
t[j] 0 ;
}