网友您好, 请在下方输入框内输入要搜索的题目:
下列给定的程序中,函数hn()的功能是:为一个偶数寻找两个素数,这两个素数之和等于该偶数,并将这两个素数通过形参指针传回主函数。
请改正函数fun()中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <stdio.h>
include <math.h>
void fun(int a, int *b, int *c)
{ int i,j,d,y;
for (i=3;i<=a/2;i=i+2)
/*************found**************/
{y=0;
for (j=2;j<=sqrt((double)i);j++)
if (i%j==0) y=0;
if (y==1)
/*************found**************/
{ d=i-a;
for (j-2;j<=sqrt((double)d);
j++)
if (d%j==0) y=0;
if (y=-1)
{*b=i; *c=d;}
}
}
}
main ()
{ int a,b,c;
do
{ printf("\nInput a: ");
scanf ("%d", &a); }
while (a%2);
fun (a, &b, &c);
printf ("\n\n%d=%d+%d\n", a,b,c);
}
参考答案