去0后输出数字

Signed-off-by: leo12025 <leo12025@outlook.com>
This commit is contained in:
2025-08-04 11:24:17 +08:00
parent 3e37187d3f
commit 62dcfa5215

View File

@@ -1,14 +1,20 @@
#include "iostream" #include "iostream"
using namespace std; using namespace std;
//最小的n int n, r, s = 0, t = 1;
float s=0,n=1;
int main() { int main() {
while (s<5) { cin >> n;
s=s+1/n; while (n > 0) {
n++;//n=n+1 n+=1 r = n % 10; // 将原数的最后一位取出
//cout <<s<<"|"<<1.0/n<<"|"<<n<<endl; n = n / 10;
if (r == 0) {
continue;
} else {
s += r * t; // 将 尾数r 乘上 位权 加到 新数s里
t *= 10; // 下一次的数字在更高一位
} }
cout <<n<<endl; }
cout << s << endl;
return 0; return 0;
} }