新人求教!为什么出不来正确结果呢
#include<stdio.h>float sum(int n1,int n2,int n3)
{
//int n1=100,n2=50,n3=10;
float s1=0,s2=0,s3=0,k,s;
for(k=1;k<=n1;k++)
{
s1+=k;//1~n1的平方和
return s1;
}
for(k=1;k<=n2;k++)
{
s2=s2+k*k;//1~n2的平方和
return s2;
}
for(k=1;k<=n3;k++)
{
s3=s3+1/k;//1~n3的倒数和;
return s3;
}
//s=s1+s2+s3;
//return s;
}
int main()
{
float s,s1,s2,s3;
s=s1+s2+s3;
sum(100,50,10);
printf("%f\n",s);
return 0;
}