首页 > 其它 > 题目详情
计算并输出3到n之间所有素数的平方根之和,为什么下面的程序不行#include #include double fun(
题目内容:
计算并输出3到n之间所有素数的平方根之和,为什么下面的程序不行
#include
#include
double fun(int n)
{int i,j;float sum;
for(i=3;ii)
sum+=sqrt(i);
}
main()
{
int n;
double sum;
FILE *out;
printf("\n\nInput n:");
scanf("%d",&n);
sum=fun(n);
printf("\n\nsum=%f\n\n",sum);
out=fopen("out.dat","w");
for (n = 0; n fprintf(out,"%f\n",fun(n+80));
fclose(out);
}优质解答
这样改 就可以:
double fun(int n)
{int i,j;float sum=0;
for(i=3;i
#include
#include
double fun(int n)
{int i,j;float sum;
for(i=3;ii)
sum+=sqrt(i);
}
main()
{
int n;
double sum;
FILE *out;
printf("\n\nInput n:");
scanf("%d",&n);
sum=fun(n);
printf("\n\nsum=%f\n\n",sum);
out=fopen("out.dat","w");
for (n = 0; n fprintf(out,"%f\n",fun(n+80));
fclose(out);
}
优质解答
double fun(int n)
{int i,j;float sum=0;
for(i=3;i
本题链接: