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 G18583301777 @ 2024-11-19 13:28:56
#include <iostream>
using namespace std;
int main(){
long long n;
cin>>n;
while(true){
if(n==1){
break;
}else 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";
return 0;
}
by G18583301777 @ 2024-11-19 13:29:54
基础的代码
by G18583301777 @ 2024-11-19 13:31:36
能关吗?