From 62dcfa52155fdac28b601c4089a6270e0311a098 Mon Sep 17 00:00:00 2001 From: leo12025 Date: Mon, 4 Aug 2025 11:24:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB0=E5=90=8E=E8=BE=93=E5=87=BA=E6=95=B0?= =?UTF-8?q?=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: leo12025 --- test01/main.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/test01/main.cpp b/test01/main.cpp index fd1de93..6e73397 100644 --- a/test01/main.cpp +++ b/test01/main.cpp @@ -1,14 +1,20 @@ #include "iostream" using namespace std; -//最小的n -float s=0,n=1; +int n, r, s = 0, t = 1; + int main() { - while (s<5) { - s=s+1/n; - n++;//n=n+1 n+=1 - //cout <> n; + while (n > 0) { + r = n % 10; // 将原数的最后一位取出 + n = n / 10; + if (r == 0) { + continue; + } else { + s += r * t; // 将 尾数r 乘上 位权 加到 新数s里 + t *= 10; // 下一次的数字在更高一位 + } } - cout <