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
blondinia [14]
3 years ago
13

Write a function that receives an integer (n) argument and then computes the following based on the value of the integer: While

the value of n is greater than 1, replace the integer with half of its value (n/2) if the integer is even. Otherwise, replace the integer with three times its value, plus 1 (3*n + 1). Make provision to count the number of values in (or the length of) the sequence that results. Test your function: If n = 10, the sequence of integers is 5, 16, 8, 4, 2, 1 and so the length is 6. Make a plot of the length of the sequence that occurs as a function of the integers from 2 to 30. For example, when n = 10, the length is 6 while for n = 15, the length is 17.
Computers and Technology
1 answer:
777dan777 [17]3 years ago
5 0

Answer:

#include <iostream>

using namespace std;

int func(int n)//function..

{

   if(n>1)

   {

       if(n%2==0)//checking if the number is even.

       {

           return n/2;

       }

       else

       {

           return (3*n+1);

       }

   }

}

int main() {

   int num;//taking input of the n.

   cin>>num;

   while(num>1)//looping while the value of num is greater than 1.

   {

       int a=func(num);//calling function.

       cout<<a<<" ";//printing .

       num=a;//changing the value of num.

   }

return 0;

}

Input:-

10

Output:-

5 16 8 4 2 1

Explanation:

I have created the function named func. Then returning the values according to the problem.In the main function taking the input of integer num. Then calling a loop and calling the function till the value of n is greater than 1 and printing all the values returned by the function.

You might be interested in
________ is a markup language that allows for tagging selected elements of the content of documents for their meanings and is us
trasher [3.6K]

Answer:

E)nXML

Explanation:

XML is a short for Extensible Markup Language. It is a markup language like the Hypertext markup language (HTML) and are both used in the development of web applications. However while the HTML describes the content of the Web page that is the graphics, images and videos and how they are displayed, the XML handles the description of data and information formats, their storage and the transportation and sharing over the internet.

4 0
3 years ago
Read 2 more answers
I need the SQL statements for these questions:
zimovet [89]

Answer:

Explanation:

/* From the information provided, For now will consider the name of table as TRIPGUIDES*/

/*In all the answers below, the syntax is based on Oracle SQL. In case of usage of other database queries, answer may vary to some extent*/

1.

Select R.Reservation_ID, R.Trip_ID , C.Customer_Num,C.Last_Name from Reservation R, Customer C where C.Customer_Num=R.Customer_Num ORDER BY C.Last_Name

/*idea is to select the join the two tables by comparing customer_id field in two tables as it is the only field which is common and then print the desired result later ordering by last name to get the results in sorted order*/

2.

Select R.Reservation_ID, R.Trip_ID , R.NUM_PERSONS from Reservation R, Customer C where C.Customer_Num=R.Customer_Num and C.LAST_NAME='Goff' and C.FIRST_NAME='Ryan'

/*Here, the explaination will be similar to the first query. Choose the desired columns from the tables, and join the two tables by equating the common field

*/

3.

Select T.TRIP_NAME from TRIP T,GUIDE G,TRIPGUIDES TG where T.TRIP_ID=TG.TRIP_ID and TG.GUIDE_NUM=G.GUIDE_NUM and G.LAST_NAME='Abrams' and G.FIRST_NAME='Miles'

/*

Here,we choose three tables TRIP,GUIDE and TRIPGUIDES. Here we selected those trips where we have guides as Miles Abrms in the GUIDES table and equated Trip_id from TRIPGUIDES to TRIP.TRIP_Name so that can have the desired results

*/

4.

Select T.TRIP_NAME

from TRIP T,TRIPGUIDES TG ,G.GUIDE

where T.TRIP_ID=TG.TRIP_ID and T.TYPE='Biking' and TG.GUIDE_NUM=G.GUIDE_NUM and G.LAST_NAME='Boyers' and G.FIRST_NAME='Rita'

/*

In the above question, we first selected the trip name from trip table. To put the condition we first make sure that all the three tables are connected properly. In order to do so, we have equated Guide_nums in guide and tripguides. and also equated trip_id in tripguides and trip. Then we equated names from guide tables and type from trip table for the desired results.

*/

5.

SELECT C.LAST_NAME , T.TRIP_NAME , T.START_LOCATION FROM CUSTOMER C, TRIP T, RESERVATION R WHERE R.TRIP_DATE='2016-07-23' AND T.TRIP_ID=R.TRIP_ID AND C.CUSTOMER_NUM=R.CUSTOMER_NUM

/*

The explaination for this one will be equivalent to the previous question where we just equated the desired columns where we equiated the desired columns in respective fields and also equated the common entities like trip ids and customer ids so that can join tables properly

*/

/*The comparison of dates in SQL depends on the format in which they are stored. In the upper case if the

dates are stored in the format as YYYY-MM-DD, then the above query mentioned will work. In case dates are stored in the form of a string then the following query will work.

SELECT C.LAST_NAME , T.TRIP_NAME , T.START_LOCATION FROM CUSTOMER C, TRIP T, RESERVATION R WHERE R.TRIP_DATE='7/23/2016' AND T.TRIP_ID=R.TRIP_ID AND C.CUSTOMER_NUM=R.CUSTOMER_NUM

*/

6.

Select R.RESERVATION_ID, R.TRIP_ID,R.TRIP_DATE FROM RESERVATION R WHERE R.TRIP_ID IN

{SELECT TRIP_ID FROM TRIP T WHERE STATE='ME'}

/*

In the above question, we firstly extracted all the trip id's which are having locations as maine. Now we have the list of all the trip_id's that have location maine. Now we just need to extract the reservation ids for the same which can be trivally done by simply using the in clause stating print all the tuples whose id's are there in the list of inner query. Remember, IN always checks in the set of values.

*/

7.

Select R.RESERVATION_ID, R.TRIP_ID,R.TRIP_DATE FROM RESERVATION WHERE

EXISTS {SELECT TRIP_ID FROM TRIP T WHERE STATE='ME' and R.TRIP_ID=T.TRIP_ID}

/*

Unlike IN, Exist returns either true or false based on existance of any tuple in the condition provided. In the question above, firstly we checked for the possibilities if there is a trip in state ME and TRIP_IDs are common. Then we selected reservation ID, trip ID and Trip dates for all queries that returns true for inner query

*/

8.

SELECT G.LAST_NAME,G.FIRST_NAME FROM GUIDE WHERE G.GUIDE_NUM IN

{

SELECT DISTINCT TG.GUIDE_NUM FROM TRIPGUIDES TG WHERE TG.TRIPID IN {

SELECT T.TRIP_ID FROM TRIP T WHERE T.TYPE='Paddling'

}

}

/*

We have used here double nested IN queries. Firstly we selected all the trips which had paddling type (from the inner most queries). Using the same, we get the list of guides,(basically got the list of guide_numbers) of all the guides eds which were on trips with trip id we got from the inner most queries. Now that we have all the guide_Nums that were on trip with type paddling, we can simply use the query select last name and first name of all the guides which are having guide nums in the list returned by middle query.

*/

4 0
3 years ago
. The _____________ is the responsibility of the CISO, and is designed to reduce incidence of accidental security breaches by or
irinina [24]

Answer: SETA program

Explanation:

 The SETA program is basically stand for the security, education, training and awareness. It is basically used to reduce the accidental security which is break by the organization member such as employees, vendors and contractors.

The SETA program provided various benefits to the organization as it improve the behavior of the employees.It basically enhance the training and education program by focus and concentrate on the information security.

It can also inform he member of the organization about the report of violating many policies.

7 0
3 years ago
Identify the device used to convert an information signal to a signal compatible with the medium over which it is being transmit
seropon [69]

Answer:

A modulator

Explanation:

This device is called a modulator and it does the task of modulation. The act of modulation influences data information on the carrier, allowing signal to be sent over a bandpass frequency range.

The Modulator is what controls an input audio signal which is called a carrier. It does not make a sound. What it does instead is to change the original carrier sound wave. The work of the Modulator as evident in the question is the conversion of information signal to a signal compatible with the medium over which it is going to be transmitted.

7 0
3 years ago
Which of the following statements accurately describes the early history of digital recording?
Alchen [17]
I would like to say that it was D. If I am not correct, try asking this in history.
6 0
3 years ago
Other questions:
  • Which transfer of learning occurs when the performance of a maneuver interferes with the learning of another maneuver?
    6·1 answer
  • Write thanks to the IT teacher at the end of grade 5
    7·1 answer
  • The first computer (the eniac was how big
    8·1 answer
  • EASY POINTS
    5·1 answer
  • What is meant by polling mode in communication between software andUART and what is its disadvantage as compared to interrupt mo
    14·1 answer
  • The method main of a class is called when you instantiate an object of that class like this: Box myBox = new Box();
    9·1 answer
  • ? An attempt to harm damage or cause threat to a system or network is broadly termed as
    9·1 answer
  • What is TSM Hamlinz’s discord
    6·2 answers
  • 4.9 Code Practice: Question 4
    10·1 answer
  • Only cool people answer this question.<br><br><br><br><br> are you cool?
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!