#include<stdio.h> int main(){ double M,N,i,sum=0,a; scanf("%lf %lf",&M,&N); a=M ; for(i=1;i<=N;i++){ sum=sum+2*M; M=M/2; } printf("%0.2lf %.2Lf",M,sum-a); return 0; }答案错误,求解
#include<stdio.h> #include<math.h> int main() { double M,N; double i=1.0,h=0.0,s=0.0,sum=0.0; scanf("%lf%lf",&M,&N); h=M*pow(1.0/2.0,N); while(N) { s=s+M*pow(1.0/2.0,N)*2.0; N--; } // for(i=1.0;i<=N;i++) // { // s+=M/pow(2.0,i)*2.0; // } sum=s+M; printf("%.2lf %lf",h,sum); return 0; } 我也用的这个函数 为什么第一个答案对 第二个不对 求各位大佬解答 谢谢
#include<stdio.h> int main() { double M,S,H; int N,n; n=0; scanf("%lf %d",&M,&N); S=M; while(N!=n){ M=M/2; H=M*2; S+=H; n++; } printf("%.2lf,%.2lf\n",M,S-M*2); return 0; } 答案错误 求解
#include<stdio.h> float M,H,X,J; int N,i; int main() { scanf("%f",&M); scanf("%d", &N); H = M / 2; X = M; J = H; for (i = 1; i < N; i++) { X += J * 2; H = H / 2; J = H; } printf("%.2f %.2f", H, X); return 0; }
#include<stdio.h> int main(){ int k,n; double m,sum,s; scanf("%lf%d",&m,&n); sum=k=0.0; while(++k){ sum+=m; m/=2; sum+=m; if(k==n){ s=m; break; } } printf("%.2lf %.2lf",s,sum-m); return 0; }
#include "stdio.h" int main() { float m,i,n,sum=0,gao; scanf("%f",&m); scanf("%f",&n); gao=m; //用另一个变量替换m,来保证m的数值不变。 for(i=1;i<=n;i++) { gao=gao/2.0; sum=sum+gao; } printf("%.2f%.2f",gao,sum+=m); }
#include<stdio.h> int main() { int i; float m,n,sum=0,gao=0; scanf("%f%f",&m,&n); gao=m; for(i=0;i<n;i++) { sum=sum+2*gao; gao=gao/2; } printf("%.2f %.2f",gao,sum-m); return 0; }
A+B for Input-Output Practice (IV) (C语言代码)浏览:484 |
愚蠢的摄影师 (C++代码)浏览:980 |
A+B for Input-Output Practice (III) (C语言代码)浏览:594 |
C二级辅导-公约公倍 (C语言代码)浏览:537 |
C二级辅导-阶乘数列 (C语言代码)浏览:583 |
模拟计算器 (C语言代码)浏览:2366 |
C语言程序设计教程(第三版)课后习题10.5 (C语言代码)浏览:985 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:550 |
1218题求大神帮忙看看怎么不能过浏览:759 |
半数集问题 (C语言代码)浏览:968 |
昵称头想破 2020-05-26 10:19:12 |
printf("%0.2lf %.2Lf",M,sum-a);
昵称头想破 2020-05-26 10:19:36 |
把0删了