#include <stdio.h>
int main()
{
int m,n,i;
double sum;
scanf("%d%d",&m,&n);
sum = 0;
for(i=m;i<=n;i++)
{
sum += 1.0/i;
}
printf("%.3lf\n",sum);
return 0;
}
很简单啊,直接加不就得了
核心代码如下
float sum=0.0;
for(int k=m;k<=n;k++){
sum+=1.0/m;
}
cout<<sum;