c语言,80分,WA为输入98.5时,请大佬看看错哪了!!!

P1423 小玉在游泳

printf为什么要用%d啊,那是给int用的,用%f
by G111118 @ 2023-08-12 00:05:46


@[G111118](/user/774430) i就是int类型呀,是用%d吧
by Morningstar01 @ 2023-08-12 10:30:51


``` #include <stdio.h> #include<math.h> int main() { double s, n=2.0,sum=2.0; int i=1; scanf("%lf", &s); while(sum < s){ n *= 0.98; sum += n; i++; } printf("%d", i); return 0; } ```
by G111118 @ 2023-08-12 13:45:13


@[Morningstar01](/user/1054113) 为什么要用for循环 用while判断直到大于等于终点距离啊
by G111118 @ 2023-08-12 13:45:53


非要用for的话直接for(i=1;;i++)
by G111118 @ 2023-08-12 13:47:12


@[Morningstar01](/user/1054113) ```cpp #include <iostream> using namespace std; int main() { long double a=2, sum=0, step=0, target; cin >> target; while(sum < target) { sum += a; a = a/100*98; step++; } cout << step; return 0; } ``````
by z_perfect @ 2023-08-15 15:24:58


应该能看懂吧
by z_perfect @ 2023-08-15 15:25:25


|