去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"
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 <<s<<"|"<<1.0/n<<"|"<<n<<endl;
cin >> n;
while (n > 0) {
r = n % 10; // 将原数的最后一位取出
n = n / 10;
if (r == 0) {
continue;
} else {
s += r * t; // 将 尾数r 乘上 位权 加到 新数s里
t *= 10; // 下一次的数字在更高一位
}
cout <<n<<endl;
}
cout << s << endl;
return 0;
}