zhangxiuping1393 @ 2022-08-12 21:15:10
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
while (n != 1) {
if (n % 2 != 0) {
cout << n << "*" << 3 << "+" << 1 << "=";
n = n * 3 + 1;
cout << n << endl;
} else if (n % 2 == 0) {
cout << n << '/' << 2 << '=';
n = n / 2;
cout << n << endl;
}
if (n == 1)
cout << "End";
}
return 0;
}
by ykzzldz @ 2022-08-12 21:21:14
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
while (1) {
if (n == 1)
{
cout << "End";
return 0;
}
if (n % 2 != 0) {
cout << n << "*" << 3 << "+" << 1 << "=";
n = n * 3 + 1;
cout << n << endl;
} else if (n % 2 == 0) {
cout << n << '/' << 2 << '=';
n = n / 2;
cout << n << endl;
}
}
return 0;
}
@zhangxiuping1393
by tyzc114514 @ 2022-08-12 21:21:24
@zhangxiuping1393 ,你应该把cout<<"End";写在循环外面,把if (n == 1)删掉
by tyzc114514 @ 2022-08-12 21:22:17
@ykzzldz ,你忘了输出End
by zhangxiuping1393 @ 2022-08-12 21:23:18
多谢,过了
@liuzejiang
by ykzzldz @ 2022-08-12 21:23:34
@liuzejiang我把它提上面了/kk
by tyzc114514 @ 2022-08-12 21:24:09
@ykzzldz ,对不起,没看到
by ykzzldz @ 2022-08-12 21:25:25
@liuzejiang不然判断会错