Yu09217777 @ 2022-11-06 10:20:25
#include <bits/stdc++.h>
using namespace std;
int main(){
long long n;
cin >> n;
while (n != 1){
if (n % 2 == 1){
cout << n << " * 3 + 1 = " << n * 3 + 1 << endl;
n = n * 3 + 1;
}else if (n % 2 == 0){
cout << n << " / 2 = " << n / 2 << endl;
n = n / 2;
}
}
cout << "End" << endl;
return 0;
}
by OoXiao_QioO @ 2022-11-06 10:29:40
@Yu09217777 输出部分,你加了空格,删掉就行了
by Yu09217777 @ 2022-11-06 10:32:17
@OoXiao_QioO 谢谢
by Hanker @ 2022-11-06 10:53:30
首先,你的输出里应该没有空格,你加了一个空格
cout << n << " / 2 = " << n / 2 << endl;
#include <bits/stdc++.h>
using namespace std;
bool J(int n){
if(n % 2 == 1){
return true;
}
return false;
}
int main(){
long long n,m;
cin>>n;
while(n != 1){
if( J(n) ){
m = n;
n = n*3+1;
cout << m << "*3+1=" << n << endl;
}else{
m = n;
n = n / 2;
cout << m << "/2=" << n << endl;
}
}
cout << "End" << endl;
return 0;
}
本人根据你的代码调整了一下\
以后写代码一定要注意细节啊