#include <stdio.h>
#include <stdlib.h>
int main()
{
int n;
double first, needs, target, M;
scanf("%lf", &target);
first = 2.0;
n = 1;
needs = first;
M = first;
while (1) //死循环
{
if (needs > target) //判断是否符合条件
{
printf("%d\n", n);
break;
}
M = M * 0.98; //每一步为上一步的98%,M(=2.0)的累积
needs += M; //总共游的距离needs(=2.0)的累加
n++;
}
return 0;
}
转载于:https://www.cnblogs.com/Tristan-Adams/p/9641738.html
本文展示了一个使用C语言编写的程序,通过无限循环计算并累加距离直到达到目标值。程序首先读取目标距离,然后初始化变量并开始循环。在循环中,每一步的距离会递减,并累加到总距离中,直到总距离大于等于目标值。
763

被折叠的 条评论
为什么被折叠?



