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
In MS Word we can merga cells true or false​
sergey [27]
In this video I showed you all of the locations for all items in Wacky Wizards!! I hope you enjoyed and please like and subscribe. Piece out!!!
7 0
2 years ago
Read 2 more answers
Implement one array of the English alphabet (26 characters). a) Create a function, getLetters() to cast and generate the array.
WARRIOR [948]

#include <fstream>

#include <iostream>

#include <iomanip>

#include <cstring>

#include <cstdlib>

using namespace std;

// Function Declarations

void display(char alphabets[],int MAX_SIZE);

void reverse(char alphabets[],int MAX_SIZE);

void swap(char &ch1,char &ch2);

int main() {

 //Declaring constant

const int MAX_SIZE=26;

 

//Declaring a char array

char alphabets[MAX_SIZE];

 

//Populating the array with alphabets

for(int i=0;i<MAX_SIZE;i++)

{

 alphabets[i]=(char)(65+i);

 }

 

 cout<<"Original: ";

 display(alphabets,MAX_SIZE);

 reverse(alphabets,MAX_SIZE);

 cout<<"Reversed: ";

 display(alphabets,MAX_SIZE);

 return 0;

}

//This function will display the array contents

void display(char alphabets[],int MAX_SIZE)

{

 for(int i=0;i<MAX_SIZE;i++)

 {

    cout<<alphabets[i]<<" ";

 }

 cout<<endl;

}

//This function will reverse the array elements

void reverse(char alphabets[],int MAX_SIZE)

{

 int first,last;

 first=0;

 last=MAX_SIZE-1;

 

 while(first<last)

 {

   

    swap(alphabets[first],alphabets[last]);

    first++;

    last--;

   

 }

}

void swap(char &ch1,char &ch2)

{

 char temp;

 temp=ch1;

 ch1=ch2;

 ch2=temp;

6 0
1 year ago
Whats the relationship between the CPU and motherboard
Mashcka [7]

Answer:

Both perform processes vital to running the computer's operating system and programs -- the motherboard serves as a base connecting all of the computer's components, while the CPU performs the actual data processing and computing.

Explanation:

6 0
3 years ago
In your own words, what is pair-programming? What is the role of the driver? What is the role of the navigator? What are some be
KATRIN_1 [288]

<u>Paired programming:</u>

Paired programming is a new technique where one person gets one another to<em> write the code</em>. Here one will write the code and other will start verifying as the type.

So we might think it is waste to employ two person for same task but it is not so. There are many <em>benefits in incorporating this technique</em>. Let us see those benefits one by one.

  • <em>Inter-personal skill gets improved </em>
  • <em>Lower amount of coding mistake </em>
  • <em>Learn from each other </em>
  • <em>Peer review enhance collaboration </em>

Challenges expect to arise during pair-programming

  • Two heads are superior to one. On the off chance that the driver experiences a <em>hitch with the code</em>, there will be two of them who'll take care of the issue.  
  • Builds up your <em>staff's relational aptitudes</em>. Working together on a solitary venture encourages your group to welcome the estimation of <em>correspondence and collaboration.  </em>

Overcome Method

The most ideal approach to move <em>toward blending</em> is to accomplice two software engineers and have them share a PC. The pair ought to have the option to choose how to part the work, and it is prudent that they should <em>switch jobs frequently.</em>

7 0
3 years ago
Which of these benefits can be achieved whensoftware is restructured?
Ivenika [448]

Answer:

iv. all of the given options

Explanation:

This is the correct answer because this is what happens when software is restructured.

<em>PLEASE</em><em> </em><em>DO MARK</em><em> </em><em>ME AS</em><em> </em><em>BRAINLIEST</em><em> </em><em>IF</em><em> </em><em>MY ANSWER</em><em> </em><em>IS HELPFUL</em><em> </em><em>;</em><em>)</em><em> </em>

4 0
3 years ago
Other questions:
  • What shooting position is commonly used when hunting with a shotgun?
    14·2 answers
  • Less than 40 percent of teens have used marijuana within the past year. True or false?
    8·1 answer
  • Why is it important to cite your sources?
    8·2 answers
  • Which browser should you choose if you want all viewing information except thumbnail previews of websites?
    15·2 answers
  • Please help explain this calculator code.
    15·1 answer
  • Discuss how sentiment analysis works using big data?<br>​
    13·1 answer
  • EASY POINTS who is your favorite in family<br> 1. mom<br> 2. dad<br> 3. sister<br> 4. brother
    10·2 answers
  • The technique helps you explore possible risks by providing access to risk areas identified in the past. It also provides the so
    10·1 answer
  • 8.5 Edhesive Code Practice
    14·1 answer
  • Taking control of admin functionality and misusing sensitive data that are unauthorized to access are due to.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!