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
Aleks [24]
3 years ago
15

Create a function (prob3_6) that will do the following: Input a positive scalar integer x. If x is odd, multiply it by 3 and add

1. If the given x is even, divide it by 2. Repeat this rule on the new value until you get 1, if ever. Your program will output how many operations it had to perform to get to 1 and the largest number along the way.
Computers and Technology
1 answer:
aniked [119]3 years ago
5 0

Answer:

Following are the program in python language

def prob3_6(k): #function definition

  c = 0 #variable declaration

  while k != 1: #iterating the while loop

      print(k) #print k

      if k % 2 == 0:#check if condition  

          k= k // 2 #divisible by 2

      else: #else condition

          k = k * 3 + 1  

      c = c + 1

  print(k) #print k

  print c #print count

prob3_6(3)#function call

Output:

3

10

5

16

8

4

2

1

7

Explanation:

Following are the description of program

  • Create a function "prob3_6" in this function we passing an integer parameter of type "int" named "k".
  • Inside that function we declared a variable "c" of type "int" that is used for counting purpose .
  • After that we iterated the while for print the value of when it is not equal to 1 .
  • We check if condition when k gives 0 on modulus then k is divisible by 2 otherwise else block will be executed in the else part we multiply by 3 to k and add 1 to the k variable .
  • Finally print "k" and "c"

You might be interested in
Write a program that asks the user to enter a birth year. the program should then indicate which generation a person of that yea
USPshnik [31]
Something like the following. Also you need to give what language you are using. Anyways, you should be able to convert this to your language of choice. 

<script type="text/javascript">
function checkGeneration() { 
   var gen = ["Baby Boomer ","Generation X","Xennials","Generation Y"];
   var reversestr = "";
   var getyear = window.prompt("Enter a 3 digit number: ");
    if (parseInt(getyear) <= 1964) {
        alert(gen[0]);   
    } else if(parseInt(getyear) <= 1979) {
        alert(gen[1]);
    } else if(parseInt(getyear) <= 1985) {
        alert(gen[2]);               
   }  else if(parseInt(getyear) <= 1995) {
        alert(gen[3]);
   }
 }
checkGeneration();
</script>
7 0
2 years ago
Who was the creator of the game Fnaf?
Lisa [10]
"Scott Cawthon" did that.........
8 0
3 years ago
Read 2 more answers
Any file that contains data but not instructions for your computer is not considered software
DIA [1.3K]
True. 

But then again, partly false. A .deb file (Debian, Ubuntu Linux) contains data, but that data needs to be installed and marked executable to make the software.

But i would still say true.
5 0
2 years ago
Find the equation of a line which has 10 points the following two coordinates: (4, 0) and (3, 4)​
alex41 [277]

Answer:

The equation of the line is y = -4·x + 16

10 points on the line include;

(0, 16), (1, 12), (2, 8), (3, 4), (4, 0), (5, -4), (6, -8), (7, 12), (8, -16), (9, -20), and (10, -24)

Explanation:

The given points through which the line passes are;

(4, 0) and (3, 4)

The slope, 'm', of the line is given as follows;

Slope, \, m =\dfrac{y_{2}-y_{1}}{x_{2}-x_{1}}

Therefore, the slope of the line is (4 - 0)/(3 - 4) = -4

In point and slope form we can get;

\dfrac{y-0}{x-4} = -4

The equation of the line in point and slope form is therefore;

y = -4·(x - 4) = -4·x + 16

The equation of the line in slope and intercept form is

y = -4·x + 16

10 points on the line are obtained using the equation of the line and the desired x-values input into cells on MS Excel and presented here as follows;

(0, 16), (1, 12), (2, 8), (3, 4), (4, 0), (5, -4), (6, -8), (7, 12), (8, -16), (9, -20), and (10, -24)

8 0
2 years ago
In a packet voice communications system, a source transmits packets containing digitizedspeech to a receiver. Because transmissi
omeli [17]

The answer & explanation for this question is given in the attachment below.

5 0
3 years ago
Other questions:
  • Jill needs to create a chart for technology club that shows what percentage of total students in the school play video games. Wh
    11·2 answers
  • You use the _____ sheet in the format cells dialog box to position data in a cell by centering it, for example.​
    8·1 answer
  • Open a command prompt on PC1. Issue the command to display the IPv6 settings. Based on the output, would you expect PC1 to be ab
    7·1 answer
  • An example of software most commonly associated with productivity software is ____.
    12·1 answer
  • Which is a correctly formatted Python tuple?
    9·1 answer
  • By using the search functionality within a twitter stream, users can filter for:
    9·1 answer
  • Quinton is having trouble learning Spanish because he keeps reverting back to the grammatical structures of his native English l
    6·1 answer
  • Which command is used to copy entire folder structures between volumes or across a network while maintaining all NTFS file permi
    10·1 answer
  • A type of authentication that requires the user to provide something that they know, such
    6·1 answer
  • imagine that you are explaining the art of visual comparison to a group of photography students. You are mentoring. What do you
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!