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
The most common types of utility programs fall into these categories.
avanturin [10]

Answer:

file management

Explanation:

correct me if I wrong

7 0
3 years ago
Chelsea is writing a paper about the value of running every day. She wrote this thesis statement:
Masteriza [31]

Answer:

no cloo

Explanation:

8 0
3 years ago
Introduction to graphic design please help! Define the four terms: design ,art,decoration , and visual literacy. Describe how th
erastovalidia [21]
Graphic design involves activities , usually done on the computer in which pictures, graphs, text and other elements are combined as a edit to books, magazines, advertisements. 
Activities which are part from this job are:
Design: the creation of ideas, plans and finally creation of object, pictures,...
Art: expressing the imagination through different ways of expression/ 
Decoration: adding something to the graphic design in order to look and act nicer
Visual literacy: the ability to understand existing trends and to learn new ones
8 0
4 years ago
An attribute is a(n)?
steposvetlana [31]

Answer:

hjqnajiwjahhwhaiwnaoai

6 0
3 years ago
Read 2 more answers
A company has a custom object named Region. Each account in salesforce can only be related to one region at a time, but this rel
dezoksy [38]

Answer:

Master - detail relationship

Explanation:

Master-detail relationship is the type of relationship that appears just like parent-child relationship, Therefore, Master-detail relationship can be defined both between standard object or custom object. The detail object receives the security and sharing settings that's also given to the master object, automatically.

8 0
3 years ago
Other questions:
  • What feature did the 32X add to the Sega Genesis?
    13·1 answer
  • A type of font that has a decorative tail is A.Serif font B. Sans serif font C. Bubbles font D. Reading font
    7·1 answer
  • WHAT DOES THE WORD MONOCHROME MEAN?
    11·1 answer
  • What are the differences between the various EHRs?
    9·1 answer
  • Sam wants to move across the text and his documents to add data at predefined stops. Which key will Hughes to navigate through t
    6·1 answer
  • You are troubleshooting a mobile device with no sound output from the headset or external speakers.
    6·1 answer
  • Which marketing claim do you see on the opening screen of the new words with friends
    14·1 answer
  • Which of the following are correct? I. Hold the middle mouse button to rotate the model on the screen. II. To pan the model, hol
    15·1 answer
  • Could anyone beat my typing?<br><br> https://keyma.sh/custom/33K7C
    5·1 answer
  • The lost boy gave the correct
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!