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
What do developers do to support software products? explain to users which development process model was used to make the produc
cestrela7 [59]

Answer:

The developer develops the user manuals to support their products. And agile development process is being used to make the user manual. The technical write this, but they first talk to developers, designers, project managers, team leaders etc. and collect all the information from them. And they start making them since start of the project. They use jira, git and various version control to update this document. And all the functionalities must be mentioned accurately, as well as latest of them to ensure reliability and credibility. Devops is another automated technology being used extensively these days.

Explanation:

The answer is self explanatory.

8 0
4 years ago
What is the error in the following line: (1)<br><br> age=int(input("Enter your age:")
Ainat [17]

Answer:

14

Explanation:

6 0
3 years ago
Which tools can be used to scale an object? Check all that apply.
meriva

Answer:

format picture pane

corner sizing handles

Explanation:

7 0
3 years ago
Why is the Microsoft website considered the best source for information about pagefile.sys?​
Bumek [7]

Answer:

uyjhjyr

Explanation:

yjdhtgjyhstjsytjuttjyh

6 0
3 years ago
Which of the following would NOT be considered an agricultural pest?
Komok [63]
A dog laying amongst the crops would not be a pest, so the correct choice would be the first one.
4 0
3 years ago
Read 2 more answers
Other questions:
  • Identify the correct options to complete the following passage.
    6·1 answer
  • A species of snake lives in a rainforest. Which would be an adaptation for this
    10·2 answers
  • The internet is a worldwide assembly of computer
    11·1 answer
  • How do you activate the Slicer Tools contextual tab?
    13·1 answer
  • What Intel socket recommends the use of a liquid cooling system?
    12·1 answer
  • The amount of money you can charge to a credit card is called?
    5·2 answers
  • PLEASE HELPP!!!!!
    14·1 answer
  • When registering online for your classes you log onto to a website provided by your university. The computer and web browser tha
    6·2 answers
  • (Giving brainliest to best answer, don't make an answer if you don't know or its jumble)
    11·2 answers
  • If a company gave you a free version of their software and encouraged you to try and improve it and share it with the only commu
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!