📄 collatz.cpp
字号:
#include <iostream.h>
#include <stdlib.h>
#include "..\include\book.h"
int main(int argc, char** argv) {
int n;
if(argc != 2) {
cout << "Usage: collatz <start value>\n";
exit(-1);
}
n = atoi(argv[1]);
cout << "The start value for the Collatz sequence is: " << n << "\n";
#define ODD(X) ((X) & 1)
// Include the version with the print statement.
// The book version has no print statement.
#define ODD(X) ((X) & 1)
while (n > 1) {
if (ODD(n))
n = 3 * n + 1;
else
n = n / 2;
cout << n << " ";
}
cout << "\n";
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -