rui_de_aihao @ 2024-10-23 20:55:55
如标题所示
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
while (n!= 1) {
if (n % 2 == 1)
cout << n << "*3+1=" << n * 3 + 1 <<endl;n = n * 3 + 1;
else
cout << n << "/2=" << n / 2 <<endl;n = n / 2;
}
cout << "End" ;
return 0;
}
代码
by DDD_et @ 2024-10-23 20:58:44
@rui_de_aihao
这不是 python 啊,你在 if
和 else
里面都写了两句语句,正确情况是把中间的分号改为逗号。
比如:
cout << ... << endl;n = n * 3 + 1;
应改为:
cout << ... << endl,n = n * 3 + 1;
by rui_de_aihao @ 2024-10-23 21:00:21
@DDD_et 好的谢谢
by DDD_et @ 2024-10-23 21:01:32
@rui_de_aihao
而且这题要开 long long
。
by Lizilin20131022 @ 2024-10-23 21:02:24
开一下long long(建议)以及把第8行和第十行分号改成逗号
by rui_de_aihao @ 2024-10-23 21:03:45
@DDD_et@Lizilin20131022 谢
by rui_de_aihao @ 2024-10-23 21:05:49
@DDD_et 请问具体该怎么写呢?
by DDD_et @ 2024-10-23 21:07:52
@rui_de_aihao
就把你题目中的那两处分号改成逗号,然后把n开成 long long
就行
by rui_de_aihao @ 2024-10-23 21:10:12
@DDD_et ok
by rui_de_aihao @ 2024-10-23 21:11:18
@DDD_et 大谢
by DDD_et @ 2024-10-23 21:11:49
@rui_de_aihao
没事