You can use printf function to show some string in console.
"%d" is number format.
int collatz(int n){
int steps = 0;
printf("%d", n);
do{
if (n%2==0){
n=n/2;
steps++;
}
else{
n=3*n+1;
steps++;
}
printf("->%d", n);
}while(n!=1);
printf("
");
return steps;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…