题目描述:
求1/n^2+1/(n+1)^2......1/m^2,以n=m=0结束
#include <iostream>
#include <iomanip> //头文件
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
long n,m;
while(1){
cin>>n>>m;
if(n==0&&m==0)
break;
double num=0;
for(int i=n;i!=m;i++){
num+=1.0/i*i;//一定要用1.0 而不是1 是一个陷阱
}
cout<< fixed<<showpoint<<setprecision(5)<<num<<endl; // 关于c++如何输出小数点后几位的方法(可以用c的printf暴力输出)
}
return 0;
}