知识点:
循环控制:循环控制
#include <iostream> using namespace std; int main() { int n; int step = 0; cin >> n; while (n != 1) { if (n % 2 == 0) { n = n / 2; } else { n = n * 3 + 1; } step++; } cout << step; return 0; }
知识点:
循环控制:循环控制
#include <iostream> using namespace std; int main() { int n; int step = 0; cin >> n; while (n != 1) { if (n % 2 == 0) { n = n / 2; } else { n = n * 3 + 1; } step++; } cout << step; return 0; }