求解Hailstone峰值

#include <iostream>
#include <stdio.h>
using namespace std;
int hailstone(int n)
{
//int length = 1;
int maxValue = 0;
while(n > 1)
{
printf("%5d", n);
(n % 2) ? n=(3*n+1) : n=(n/2);
/*
* <表达式1>?<表达式2>:<表达式3>
* 在运算中,首先对第一个表达式进行检验,
* 如果为真,则返回表达式2的值;
* 如果为假,则返回表达式3的值。
*
* */
if (n > maxValue)
{
maxValue = n;
}
//length++;
}
return maxValue;
}
int main()
{
printf("Please input the number: ");
int number = 0;
scanf("%d", &number);
printf("the number is %d \n", number);
int maxValue = hailstone(number);
printf("\n The max is %d", maxValue);
return 0;
}