楼上两位的代码可能有点小问题
s += m*m+1/m;
改成
s += m*m+1.0/m;
#include
int main()
{
int n,m,i;
float sum=0;
scanf("%d%d",&m,&n);
for(i=m;i<=n;i++)
sum+=(i*i+1.0/i);
printf("%f\n",sum);
return 0;
}
double sum(int m, int n){
double s = 0.0;
while(m<=n){
s += m*m+1/m;
m++;
}
return s;
}
float sum=0;
for(i=m;i<=n;i++) {
sum+=i*i+1/i;
}