Hailstone Sequence hail sequence

Hailstone Sequence

Hailstone Sequence is now not able to prove its correctness.
Enter any integer N greater than 1, if it is an even number, then divided by 2, if it is odd, then multiplied by 1 plus 3, this number will be finally becomes 1. Particularly, when the input is 1, the sequence is 1. The formula is as follows:
Here Insert Picture Description
Code:
#include
#include
the using namespace STD;
int main (int argc, char * the argv [])
{
int * = hailstone new new int [500];
int I;
CIN >> hailstone [0];
for ( . 1 = I; I <500; I ++) {
int = pre hailstone [-I. 1];
IF (pre. 1)
BREAK; // special circumstances
else if (pre% 2
0)//偶数时
hailstone[i]=pre/2;
else
hailstone[i]=pre*3+1;//基数时
}
cout<<“hailstone(”<<hailstone[0]<<")={";
for(int j=0;j<i;j++)
cout<<hailstone[j]<<" “;
cout<<”}"<<"\n";
cout<<“数列长度:”<<i<<endl;
return 0;
}

Reference Links:
https://blog.csdn.net/artprog/article/details/50989263

Released five original articles · won praise 0 · Views 68

Guess you like

Origin blog.csdn.net/MARSHCW/article/details/104081078