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
icang [17]
2 years ago
14

Write a C++ function using recursion that returns the Greatest Common Divisor of two integers. The greatest common divisor (gcd)

of two integers, which are not zero, is the largest positive integer that divides each of the integers. For example, the god of 8 and 12 is 4.
Computers and Technology
1 answer:
kifflom [539]2 years ago
8 0

Answer:

The function is as follows:

int gcd(int num1, int num2){

   if (num2 != 0){

      return gcd(num2, num1 % num2);}

   else {

      return num1;}

}

Explanation:

This defines the function

int gcd(int num1, int num2){

This is repeated while num2 is not 2

   if (num2 != 0){

This calls the function recursively

      return gcd(num2, num1 % num2);}

When num2 is 0

   else {

This returns the num1 as the gcd

      return num1;}

}

You might be interested in
Consider the two computers A and B with the clock cycle times 100 ps and 150 ps respectively for some program. The number of cyc
Kipish [7]

Answer:

Option d) B is 1.33 times faster than A

Given:

Clock time, t_{A} = 100 ps

t_{A} = 150 ps

No. of cycles per instructions,  n_{A} = 2.0

n_{B} = 1.0

Solution:

Let I be the no. of instructions for the program.

CPU clock cycle, f_{A} = 2.0 I

CPU clock cycle, f_{B} = 1.0 I

Now,

CPU time for each can be calculated as:

CPU time, T = CPU clock cycle\times clock time

T_{A} = f_{A}\times t_{A} = 2.0 I\times 100 = 200 I ps

T_{B} = f_{B}\times t_{B} = 1.0 I\times 100 = 150 I ps

Thus B is faster than A

Now,

\frac{Performance of A}{Performance of B} = \frac{T_{A}}{T_{B}}

\frac{Performance of A}{Performance of B} = \frac{200}{150}

Performance of B is 1.33 times that of A

7 0
2 years ago
Read 2 more answers
8.3 code practice edhesive PLEASE HELP AND HURRY
NemiM [27]

Answer:

numbers = '14 36 31 -2 11 -6'

nums = numbers.split(' ')

for i in range(0, len(nums)):

  nums[i] = int(nums[i])

print(nums)

8 0
2 years ago
Coding with Loops Worksheet
BartSMP [9]

Answer:

if you give me brainliest i will answer your question

Explan

4 0
2 years ago
Read 2 more answers
To add a hyperlink to your presentation, select the text, choose Hyperlink from the Insert menu, and then
Elan Coil [88]

Answer:

I guessed D, taking it right now, sorry if it's wrong

Explanation:

6 0
2 years ago
An administrator is troubleshooting an endpoint whose SIP Registration Status shows "Failed: 403 Forbidden" and must obtain info
Katena32 [7]

Answer:

A and C

Explanation:

To obtain information about the case of the error the engineer would navigte thus:

Endpoint > Log Files > messages.log > (c) VCS > Maintenance > Diagnostics > Incident Reporting > View.

Cheers

8 0
3 years ago
Other questions:
  • Zoom Vacuum, a family-owned manufacturer of high-end vacuums, has grown exponentially over the last few years. However, the comp
    11·1 answer
  • Which of the following is true of two-factor authentication?
    13·1 answer
  • Implement the function pairSum that takes as parameters a list of distinct integers and a target value n and prints the indices
    11·1 answer
  • _______ view focuses on the text and content of a document, without much information on the page layout.
    7·1 answer
  • The number of square units required to cover a surface.
    13·1 answer
  • Write a test program that creates two Rectangle objects—one with width 4 and height 40 and the other with width 3.5 and height 3
    5·1 answer
  • What is the main purpose of a web crawling program
    15·1 answer
  • Why can videos be streamed from the cloud to a computer with no loss in
    5·2 answers
  • 1)What is the hydropower resources/energy?
    7·1 answer
  • 8. Choose the 3 correct statements for the code below.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!