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
HOW TO GET RID OF THESE LINES?? PLS WILL GIVE BRAINLIEST
Sladkaya [172]

Answer:

Is that your computer? Did you already try

Explanation:

  • Powering off and powering back on?
  • Or restarting it
  • It could be a school issue, like when I search something on G oogle and go to Images, it did not work and loaded very slow. But now all of a sudden, it works.
8 0
2 years ago
Read 2 more answers
What is the major difference between the intranet and extranet?
slega [8]

Explanation:

Iinternet is hudge graphicla network and intranet is small network as compare to internet

8 0
2 years ago
How can investors receive compounding returns
ANTONII [103]
If you’ve ever had a savings account, you likely know that a few cents in interest every month barely adds up. The goal is “compounding returns,” which simply means that the interest you earn each month earns additional interest, which then earns even more interest. But although a savings account will help with that, you may be lucky enough to be able to afford a cup of coffee every 10 years or so at that rate. Instead, it’s important to find a way to invest your money in a high-interest account that will earn compounding returns.

I hope this helps you out ;)
3 0
3 years ago
Given an array as follows
slava [35]

Answer:

1) Method calcTotal:

  1. public static long calcTotal(long [][] arr2D){
  2.        long total = 0;
  3.        
  4.        for(int i = 0; i < arr2D.length; i++ )
  5.        {
  6.            for(int j = 0; j < arr2D[i].length; j++)
  7.            {
  8.                total = total + arr2D[i][j];
  9.            }
  10.        }
  11.        
  12.        return total;
  13.    }

Explanation:

Line 1: Define a public method <em>calcTotal</em> and this method accept a two-dimensional array

Line 2: Declare a variable, total, and initialize it with zero.

Line 4: An outer for-loop to iterate through every rows of the two-dimensional array

Line 6: An inner  for-loop to iterate though every columns within a particular row.

Line 8: Within the inner for-loop, use current row and column index, i and j, to repeatedly extract the value of each element in the array and add it to the variable total.

Line 12: Return the final total of all the element values as an output

Answer:

2) Method calcAverage:

  1. public static double calcAverage(long [][] arr2D){
  2.        double total = 0;
  3.        int count = 0;
  4.        
  5.        for(int i = 0; i < arr2D.length; i++ )
  6.        {
  7.            for(int j = 0; j < arr2D[i].length; j++)
  8.            {
  9.                total = total + arr2D[i][j];
  10.                count++;
  11.            }
  12.            
  13.        }
  14.        
  15.        double average = total / count;
  16.        
  17.        return average;
  18.    }

Explanation:

The code in method <em>calcAverage</em> is quite similar to method <em>calcTotal</em>. We just need to add a counter and use that counter as a divisor of total values to obtain an average.

Line 4: Declare a variable, count, as an counter and initialize it to zero.

Line 11: Whenever an element of the 2D array is added to the total, the count is incremented by one. By doing so, we can get the total number of elements that exist in the array.

Line 16: Use the count as a divisor to the total to get average

Line 18: Return the average of all the values in the array as an output.

Answer:

3) calcRowAverage:

  1. public static double calcRowAverage(long [][] arr2D, int row){
  2.        double total = 0;
  3.        int count = 0;
  4.        
  5.        for(int i = 0; i < arr2D.length; i++ )
  6.        {
  7.            if(i == row)
  8.            {
  9.                for(int j = 0; j < arr2D[i].length; j++)
  10.                {
  11.                    total = total + arr2D[i][j];
  12.                    count++;
  13.                }
  14.            }
  15.            
  16.        }
  17.        
  18.        double average = total / count;
  19.        
  20.        return average;
  21.    }

Explanation:

By using method <em>calcAverage </em>as a foundation, add one more parameter, row, in the method <em>calcRowAverage</em>. The row number is used as an conditional checking criteria to ensure only that particular row of elements will be summed up and divided by the counter to get an average of that row.

Line 1: Add one more parameter, row,

Line 8-15: Check if current row index, i, is equal to the target row number, proceed to sum up the array element in that particular row and increment the counter.

5 0
2 years ago
Important tools used in the _____ phase of the DMAIC process include a project charter, a description of customer requirements,
pishuonlain [190]

Answer:

d. define

Explanation:

DMAIC is an acronym for Define, Measure, Analyze, Improve and Control is a data-driven improvement cycle used for improving processes and driving Six Sigma projects.

Important tools used in the define phase of the Define, Measure, Analyze, Improve, and Control (DMAIC) process include;

- A project charter.

- A description of customer requirements.

- Process maps.

- Voice of the Customer (VOC) data.

5 0
3 years ago
Other questions:
  • A windows host sends a tcp segment with source port number 1200 and destination port number 25. the sending host is a(n) _______
    10·1 answer
  • Martha wants to invite her coworkers to her birthday party. She uses the mail merge feature to compose and send the invitations.
    6·1 answer
  • What ipconfig command line option can be used to delete cached dns information from memory?​?
    9·1 answer
  • Write the definition of a class Counter containing: An instance variable named counter of type int. An instance variable named l
    14·1 answer
  • Hvhblfffffffff<br> eafafaefafsa
    9·2 answers
  • I need help I have questions I need answers in coding html,css,js and python.Fast
    7·1 answer
  • Are there any apps in the App Store that allow people to ask a question about any topic and have skilled professionals answer it
    6·1 answer
  • A location in memory which stores a value, the value can change as the program is running is
    12·1 answer
  • 3) The director tells you to truck left, you must:
    10·1 answer
  • PLSS HELP ASAP ILL GIVE BRAINLIES THANKS
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!