Write a program in C++ based on the hailstone problem below. The input data shou
ID: 644895 • Letter: W
Question
Write a program in C++ based on the hailstone problem below. The input data should be 1699 and 101030. Only print out the number of hailstones.
23 Let no be a given positive integer. For = 0, 1, 2, ... define The sequence stops whenever ni has the value 1. Numbers that axe generated this way are called hailstones. Write a program that generates some hailstones. The function should be used to compute and print the sequence generated by n. The output of your program might look as follows: Number of hailstones generated; 77 You will find that all the sequences you generate are finite. Whether this is true in general. is still an open question.Explanation / Answer
#include
#include
void hailstones(int n);
void hailstones(int n)
{
cout<<"Hailstones generated by "< while(n!=1)
{
cout< if(n%2==0)
n=n/2;
else
n=3*n+1;
}
}
void main()
{
int x;
clrscr();
cout<<"Enter any number";
cin>>x;
hailstones(x);
getch();
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.