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
Marrrta [24]
3 years ago
13

6. (18) 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:
natulia [17]3 years ago
7 0

Answer:

<em>The programming language is not stated, so I'll make use of C++ programming language</em>

<em>Comments are used for explanatory purpose</em>

<em>Program starts here</em>

#include<iostream>

using namespace std;

void prob_36(int n) //Declare Function

{

//Declare and Initialize nummber of operation to 0

int num = 0;

//Declare and initialize largest

int largest = 0;

while(n!=1)//Iterate until number is 0

{

if(n % 2 == 0)//Check for even

{

 n/=2;

}

else // Check for odd

{

 n*=3;

 n++;

}  

cout<<n<<'\t'; //Print result

if(largest<n) // Test for largest

{

 largest = n;

}

num++; //Increment number of operation

}

cout<<endl;

//Print number of operations

cout<<"Number of operation: "<<num<<endl;

//Print largest number along the way

cout<<"Largest number along the way: "<<largest;

}

int main()

{

int n;

//Prompt user for input

cout<<"Enter any positive integer number: ";

cin>>n;

if(n<1)

{

 cout<<"Number must be greeater than 0";

}

else

{  

prob_36(n); //Call Function

}  

return 0;

}

You might be interested in
What key do you press so you can switch tabs quickly?
ss7ja [257]
Alt and tab to switch to open applications
4 0
4 years ago
Explain vividly any operating system of your choice stating at least 3 distinguishing features of each version.
rosijanka [135]

Answer:

microsoft windows, macOS, and linux

Explanation:

if you need help let me know

7 0
4 years ago
Read 2 more answers
In which state of matter is there no particle motion?
kiruha [24]
Solid is your answer for the day
6 0
3 years ago
AN OBSTACLE OR BARRIER THAT MAY PREVENT YOU FROM ACCOMPLISHING YOUR GOAL IS:
marishachu [46]
Depends on what kind of goal.
If I gave a goal of eating 8 hot dogs then a barrier would be a physical will of your body to not eat more. It would be a limit your body can take so it’s different from a mental or other barrier.
If you wanted to cross an area of land but there is a fence in the way then that’s another type of barrier.
Or there are mental barriers. If you wanted to ask someone out to prom, you may be stopped by a mental barrier of self hatred. Feeling like you’re not good enough.

Hopefully this helps!
5 0
4 years ago
If you want to refine your Google search results by date, which option should you use?
just olya [345]
Try using ctrl, shift, delete
7 0
4 years ago
Other questions:
  • C++
    8·1 answer
  • This information is generally included on a fax cover sheet.
    15·1 answer
  • Consider the following declaration: double[] sales = new double[50]; int j; Which of the following correctly initializes all the
    11·1 answer
  • Is there a way I can put an already made sound that i created over an already made video
    6·1 answer
  • The ____ developed numerical methods for generating square roots, multiplication tables, and trigonometric tables used by early
    12·1 answer
  • 9. The voltage of a replacement capacitor must
    11·1 answer
  • Design and implement an application that plays the Hi-Lo guessing game with numbers. The program should pick a random number bet
    13·1 answer
  • On his website, Mario has a video that visitors must click to play. He wants the video to play automatically when the page loads
    9·1 answer
  • 2.4 Code Practice: Question 2
    5·1 answer
  • Help pweaseee!! Lloyd has created a validation script for a data entry form. What property should he use to test for a selected
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!