Please click on 1-2 Ads to keep this website's Study Material FREE and regularly Updated.

Program 53: Write a C++ program to find the hailstone sequence of a given number upto 1.

#include<iostream>
using namespace std;

int main()
{
	int num;
	cout<<"\nenter a number : ";
	cin>>num;
	cout<<"\nhailstone sequence :-\n"<<num;

	while(num!=1)
	{
		if(num%2==0)
		num=num/2;
		else
		num=3*num+1;
		cout<<"\t"<<num;
	}
	return 0;
}



If you have any suggestion or found any error in the above program, then do let us know at [email protected] or just comment below.