用c语言计算输出s=1+(1+根号2)+(1+根号2+根号3)+....(1+根号2+根号3+...+根号n)
注意n的值要大于1但不大于100#include<math.h>#include<stdio.h>doublefun(intn){inti;doublesum1=1,su...
注意n的值要大于1但不大于100
#include <math.h>
#include <stdio.h>
double fun(int n)
{
int i;
double sum1=1,sum=1;
for(i=1;i<=n;i++)
{
sum1=sum1+sqrt(i+1);
sum=sum+sum1;
}
return sum;
}
main()
{
int n;
double s;
FILE *out;
printf("\n\nInput n: ");
scanf("%d",&n);
s=fun(n);
printf("\n\ns=%f\n\n",s);
out=fopen("out.dat","w");
for (n = 0; n < 10; n++)
fprintf(out, "%f\n", fun(n+20));
fclose(out);
}
为什么是错的 展开
#include <math.h>
#include <stdio.h>
double fun(int n)
{
int i;
double sum1=1,sum=1;
for(i=1;i<=n;i++)
{
sum1=sum1+sqrt(i+1);
sum=sum+sum1;
}
return sum;
}
main()
{
int n;
double s;
FILE *out;
printf("\n\nInput n: ");
scanf("%d",&n);
s=fun(n);
printf("\n\ns=%f\n\n",s);
out=fopen("out.dat","w");
for (n = 0; n < 10; n++)
fprintf(out, "%f\n", fun(n+20));
fclose(out);
}
为什么是错的 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询