请编写函数fun,其功能是:计算并输出3到n之间(含3和n)所有素数的平方根之和。例如,在主函数中从键盘给n输入100后,输出为:sum=148.874270。
注意:要求n的值大于2但不大于100。部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
/**********code.c**********/
#include
#include
double fun(int n)
{
}
void main()
{
int n;
double sum;
void NONO ();
printf("\n\nInput n: ");
scanf("%d",&n);
sum=fun(n);
printf("\n\nsum=%f\n\n",sum);
NONO();
}
void NONO ()
{
/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */
int n,j;
FILE *rf,*wf;
rf = fopen("in.dat","r");
wf= fopen("out.dat","w");
for(j=0;j<10;j++)
{
fscanf(rf, "%d",&n);
fprintf(wf,"%f\n",fun(n));
}
fclose(rf);
fclose(wf);
}
/**********-code.c**********/
/**********indat**********/
-1
0
3
4
5
17
20
100
200
800
/**********-indat**********/
/**********outdat**********/
0.000000
0.000000
1.732051
1.732051
3.968119
17.659152
22.018051
148.874270
405.252548
2437.670620
/**********-outdat**********/