1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
NeX [460]
2 years ago
9

The length of a hailstone sequence is the number of terms it contains. For example, the hailstone sequence in example 1 (5, 16,

8, 4, 2, 1) has a length of 6 and the hailstone sequence in example 2 (8, 4, 2, 1) has a length of 4. Write the method hailstoneLength(int n), which returns the length of the hailstone sequence that starts with n. /** Returns the length of a hailstone sequence that starts with n, * as described in part (a). * Precondition: n > 0 */ public static int hailstoneLength(int n)
Computers and Technology
1 answer:
11111nata11111 [884]2 years ago
7 0

Answer:

Following are the program to this question:

#include <iostream> //defining header file

using namespace std;

int hailstoneLength(int n) //defining method hailstoneLength

{

int t=1; //defining integer variable assign  

while(n!=1) //define a loop that checks value is not equal to 1

{

if(n%2==0) // check even number condition

{

n=n/2; // divide the value by 2 and store its remainder value in n

t++; //increment value of t by 1.

}

else

{

n=n*3+1; //calculate and hold value in n  

t++; //increment value of t variable by 1  

}

}

return t; //return value

}

int main() //defining main method

{

int n; //defining integer variable

cout<<"Enter any number: "; //print message

cin>> n; //input value

cout<<hailstoneLength(n); //call method and print its value

return 0;

}

Output:

Enter any number: 3

8

Explanation:

Program description can be given as follows:

  • In the given C++ language program an integer method "hailstoneLength", is declared, that accepts an integer variable "n" in its parameter.
  • Inside the method, an integer variable t is declared, that assign a value that is 1, in the next line, a while loop is declared, that uses if block to check even condition if number is even it divide by 2 and increment t variable value by 1.
  • If the number is odd it will multiply the value by 3 and add 1 and increment t by 1 then it will go to if block to check value again. when value of n is not equal to 1 it will return t variable value.
  • In the main method, an integer variable "n" is used that call the method and print its return value.
You might be interested in
Point giveaway and brainliest
melamori03 [73]

Thank you, pal!

You are invited to my clubhouse!

5 0
3 years ago
Read 2 more answers
A digital computer has a memory unit with 16 bits per word. The instruction set consists of 72 different operations. All instruc
OLga [1]

Answer:

a. 7 bits b. 9 bits c. 1 kB d. 2¹⁶ - 1

Explanation:

a. How many bits are needed for the opcode?

Since there are 72 different operations, we require the number of bits that would contain 72 different operations. So, 2ⁿ ≥ 72

72 = 64 + 8 = 2⁶ + 8

Since n must be an integer value, the closest value of n that would contain 72 different operations is n = 7. So, 2⁷ = 128

So, we require 7 bits for the opcode.

b. How many bits are left for the address part of the instruction?

bits left = bits per word - opcode bit = 16 - 7 = 9 bits

c. What is the maximum allowable size for memory?

Since there are going to be 2⁹ bits to addresses each word and 16 bits  for each word, the maximum allowable size for memory is thus 2⁹ × 16 = 512 × 16 = 8192 bits.

We convert this to bytes

8192 bits × 1 byte/8 bits = 1024 bytes = 1 kB

d. What is the largest unsigned binary number that can be accommodated in one word of memory?

Since the number go from 0 to 2¹⁶, the largest unsigned binary number that can be accommodated in one word of memory is thus

2¹⁶ - 1

6 0
3 years ago
As Jason walks down the street, a large raven starts squawking at him and flapping its wings. Jason thinks to himself ‘That bird
UNO [17]

Answer:

Answer to the following question is anthropomorphism.

Explanation:

Anthropomorphism is considered as the error in the following context of the scientific reductionism. Anthropomorphize is the source of an error that needs to reconsider.

Anthropomorphism is an attribute of the human qualities, emotions, thoughts, motivation, intentions, and characteristics to the non-living beings or the nonhuman beings, things or objects.

8 0
3 years ago
What will you recommend to HP Mini 5103 Notebook?​
laiz [17]
Hey what are you guys going on with your dad today or tomorrow night
5 0
2 years ago
Kaylen has been working on his computer and notices that the screen seems to be flickering. The monitor is not turning on and of
Komok [63]

Answer:

Screen flickering is usually caused by an incompatible app or display driver. It could also be caused by a bad HDMI/VGA connection to the monitor.

Hope it helps ! :)

6 0
3 years ago
Other questions:
  • Review the given requirements using the checklist and discover possible problems with them. The following requirements are for a
    8·1 answer
  • A(n) monitoring vulnerability scanner is one that listens in on the network and determines vulnerable versions of both server an
    7·1 answer
  • A is a paid placement that appears in a search engines results page at or near the top of the results
    5·1 answer
  • Complete a graphic organizer to explain the responsibilities of a borrower
    14·1 answer
  • Write a class called SimpleSquare that has the following properties: - public int field called num - private int field called sq
    13·1 answer
  • Explain the components of Information System?​
    13·1 answer
  • identify at least three additional ethical responsibilities expected from a computer professional. In brief, explain each respon
    11·1 answer
  • It is used to select specific menu options, drag and drop options and to draw something on screen.
    6·1 answer
  • How do you write a multiplication formula in excel with an absolute refrence?
    11·1 answer
  • I WILL MARK IT BRAINLIEST FOR SURE ☺️❤️
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!