2010计算机等考二级C:50套上机程序填空题(18)

全国等级考试资料网 2022-08-23 03:47:29 72

2010计算机等考二级C:50套上机程序填空题(18)

49、给定程序中,函数fun的功能是:计算下式前n项的和作为函数值返回。

例如,当形参n的值为10时,函数返回:-0.204491。

请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。

注意:源程序存放在考生文件夹下的BLANK1.C中。

不得增行或删行,也不得更改程序的结构!

#include

double fun(int n)

{ int i, k; double s, t;

s=0;

/**********found**********/

k=__1__;

for(i=1; i<=n; i++) {

/**********found**********/

t=__2__;

s=s+k*(2*i-1)*(2*i+1)/(t*t);

/**********found**********/

k=k*__3__;

}

return s;

}

main()

{ int n=-1;

while(n<0)

{ printf("Please input(n>0): "); scanf("%d",&n); }

printf(" The result is: %f ",fun(n));

}


50、给定程序中,函数fun的功能是将不带头结点的单向链表逆置。即若原链表中从头至尾结点数据域依次为:2、4、6、8、10,逆置后,从头至尾结点数据域依次为:10、8、6、4、2。

请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。

注意:源程序存放在考生文件夹下的BLANK1.C中。

不得增行或删行,也不得更改程序的结构!

#include

#include

#define N 5

typedef struct node {

int data;

struct node *next;

} NODE;

/**********found**********/

__1__ * fun(NODE *h)

{ NODE *p, *q, *r;

p = h;

if (p == NULL)

return NULL;

q = p->next;

p->next = NULL;

while (q)

{

/**********found**********/

r = q->__2__;

q->next = p;

p = q;

list is NULL! ");

else

{ printf(" Head ");

do

{ printf("->%d", p->data); p=p->next; }

while(p!=NULL);

printf("->End ");

}

}

main()

{ NODE *head;

int a[N]={2,4,6,8,10};

head=creatlist(a);

printf(" The original list: ");

outlist(head);

head=fun(head);

printf(" The list after inverting : ");

outlist(head);

}

[ 结 束 ]

list is NULL! ");

else

{ printf(" Head ");

do

{ printf("->%d", p->data); p=p->next; }

while(p!=NULL);

printf("->End ");

}

}

main()

{ NODE *head;

int a[N]={2,4,6,8,10};

head=creatlist(a);

printf(" The original list: ");

outlist(head);

head=fun(head);

printf(" The list after inverting : ");

outlist(head);

}


[ 结 束 ]

相关资料

相关阅读