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
jeka94
3 years ago
15

Write a function "hailstone"that takes an int "n2"and prints the hailstone sequence. Hailstone Numbers:This sequence takes the n

ame hailstone as the numbers generated bounce up and down. To generate the sequence, follow these rules:a.If the number isodd multiply it by 3 and add 1 b.If the number is even, divide by two.c.Repeat until you reach number 1.Sample Inputs & Outputsn2= 3-> 10, 5, 16, 8, 4, 2, 1 n2 =6-> 3, 10, 5, 16, 8, 4, 2, 1 n2 =7-> 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1

Computers and Technology
1 answer:
givi [52]3 years ago
4 0

Answer:

Here is the C program    

#include<iostream>  //for input output functions

using namespace std;   //to identify objects like cin cout

int Hailstone(int n2);   //function declaration of function Hailstone

int main()  {  // start of main() function body

int num;   // stores number entered by user

cout<<"Enter a number: ";  // prompts user to enter a number

cin>>num;   // reads the input number

while(num!=1) {  // loop continues until the value of num becomes 1

 num = Hailstone(num);  // calls hailstone method and passes num to it

cout<<num<<"\n";  }   }  // prints the hailstone sequence

int Hailstone(int n2)  {  //function takes int n2 and prints hailstone sequence

if(n2 % 2 == 0) {  // if the number is even

return n2 /=2;  }  // divide the n2 by 2 if n2 value is even

else {  // if n2 is odd

return n2 = (3 * n2) + 1;  }  }  // multiply n2 by 3 and  add 1 if n2 is odd

 

Explanation:

The function Hailstone() takes as parameter an integer which is int type and is named is n2. This function prints the hailstone sequence. The function has an if statement that checks if the number n2 input by the user is even or odd. If the value of n2 is even which is found out by taking modulus of n2 by 2 and if the result is 0 this means that n2 is completely divisible by 2 and n2 is an even number. So if this condition evaluates to true then n2 is divided by 2. If the condition evaluates to false and the value of n2 is odd then n2 is multiplied by 3 and 1 is added.

In the main() function the user is prompted to enter a number and the  Hailstone() function is called which keeps repeating until the value of n2 reaches 1.

You might be interested in
One of the most toxic components of a computer is the _____.
defon

I would say A. because that is true but mostly for older computers

4 0
4 years ago
Scenario2: Now suppose the LAN must support both voice and data and you must choose one of these multiple access strategies in o
AleksandrR [38]

Answer:

The RTP (real time protocol) which uses the UDP ( user datagram protocol) and Real-time control protocol.

Explanation:

The RTP of a voice over IP protocol (VoIP) which is used to prioritise the transfer of video and audio data over text data. It is used for video conferencing and telephony services in an enterprise.

It uses the user-datagram protocol to transfer or access videos and audio data for its real time effect and the real-time control protocol for quality of service analysis and maintenance.

4 0
3 years ago
If you cannot find a template on your computer that was appropriate for your task, what should you do?
DanielleElmas [232]

Answer:

The correct option for this question is File.

Explanation:

5 0
3 years ago
It is safe to interchange oxygen and fuel gas hoses. A. False B. True
Marat540 [252]
False.
If you were to interchange one another it would be VERY life threatening.
6 0
4 years ago
Read 2 more answers
g Fill the validateForm function to check that the phone number is 10 characters long and that the user name is less than 11 cha
Rom4ik [11]

Answer:

function validateForm(event)

{

event.preventDefault();

var phoneNumber = form.phoneNumber.value;

var userName = form.userName.value;

if(phoneNumber.length!=10)

console.log("Phone Number is Invalid");

if(userName.length<11)

console.log("User Name is Invalid"); }

8 0
3 years ago
Other questions:
  • William is an amateur photographer who plans to create a portfolio to improve his career prospects. He wants to capture a mother
    6·1 answer
  • Technician A says that wheel speed sensors are a highly probable cause of illuminated EBC warning lamps. Technician B says that
    10·1 answer
  • The following code processes a file containing five positive numbers. What will the variable $result contain after the code is e
    13·1 answer
  • What type of IPv6 address should you use when you have multiple routers on a subnet and want hosts to use the nearest router for
    10·1 answer
  • List the memory units inside and outside of the CPU, along with short descriptions of their
    11·1 answer
  • A particular problem is currently not able to be practically solved by using an algorithm. Which of the following statements abo
    13·2 answers
  • Reverse Word Order: Write a program that reverses the order of the words in a given sentence. This program requires reversing th
    15·1 answer
  • Characteristics of the printer​
    6·1 answer
  • Which of the following describes all illustrations created by freehand?
    15·1 answer
  • A group of two or more computer systems linked together via communication devices is called:.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!