输入两个正整数n<m<10 6 ,输出 ,保留5位小数。输入包含多组数据, 结束标记为n=m=0。提示:本题有陷阱。
样例输入: 2 4 65536 655360 0 0
样例输出: Case 1: 0.42361 Case 2: 0.00001
#include<stdio.h>
int main(){
int count = 0;
while (1){
int n = 0;
int m = 0;
scanf("%d", &n);
scanf("%d", &m);
if (n == m&&n == 0){
break;
}
count++;
double sum = 0;
for (int i = n; i <= m;i++){
sum += 1.0 / i / i;
}
printf("Case %d:%.5f\n",count,sum);
}
return 0;
}
注意:n^2可能会溢出!
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有