问答题
给定程序中,函数fun的功能是用函数指针指向要调用的函数,并进行调用。规定在第二空处使fa指向函数f1,在第三空处使fb指向函数f2。当调用正确时,程序输出:
x1=5.000000,x2=3.000000,x1*x1+x1*x2=40.000000
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在
下的BLANK1.C中。不得增行或删行,也不得更改程序的结构!
#include <stdio.h>
double f1(double x)
{ return x*x;}
double f2(double x,double y)
{ return x,y;}
double fun(double a,double b)
{
/**********found**********/
______ (*f)();
double r1,r2;
/**********found**********/
f=______; /* point fountion f1 */
r1=f(a);
/**********found**********/
f=______; /* point fountion f2 */
r2=(*f)(a,b);
return r1+r2;
}
main()
{ double x1=5,x2=3,r;
r=fun(x1,x2);
printf("\nx1=%f,x2=%f,x1*x1+x1*x2=%f\n",x1,x2,r)
}
热门
试题
问答题
给定程序MODI1.C是建立一个带头结点的单向链表,并用随机函数为各结点赋值。函数fun的功能是将单向链表结点(不包括头结点)数据域为偶数的值累加起来,并且作为函数值返回。请改正函数fun中指定部位的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!#include <stdio.h>#include <stdlib.h>typedef struct aa{ int data;struct aa *next;}NODE;int fun(NODE *h){ int sum=0;NODE *p; ***********found********** p=h;while(p){ if(p->data%2==0)sum +=p->data; ***********found********** p=h->next;}return sum;}NODE *creatlink(int n){NODE *h,*p,*s;int i;h=p=(NODE *)malloc(sizeof(NODE));for(i=1;i<=n;i++){ s=(NODE *)malloc(sizeof(NODE));s->data=rand()%16;s->next=p->next;p->next=s;p=p->next i}p->next=NULL;return h;}outlink(NODE *h,FILE *pf){NODE *p;p=h->next;fprintf(pf, n nTHE LIST: n n HEAD );while (p){ fprintf(pf, ->%d ,p->data);p=p->next;}fprintf(pf, n );}outresult(int s,FILE *pf){ fprintf(pf, nThe sum of even numbers:%d n ,s);}main(){NODE *head;int even;head=creatlink (12);head->data=9000;outlink(head,stdout);even=fun(head);printf( nThe result: n );outresult(even,stdout);}