For two integers m and n, their GCD(Greatest Common Divisor) can be computed by a recursive function. Write a recursive method gcd(m,n) to find their Greatest Common Divisor. Once m is 0, the function returns n. Once n is 0, the function returns m. If neither is 0, the function can recursively calculate the Greatest Common Divisor with two smaller parameters: One is n, the second one is m mod n. Although there are other approaches to calculate Greatest Common Divisor, your program should follow the instructions of this question, otherwise you will not get the credit. Then write a testing program to call the recursive method.

Answers

Answer 1

Answer:

In Python:

def gcd(m,n):

if n == 0:

 return m

elif m == 0:

    return n

else:

 return gcd(n,m%n)

Explanation:

This defines the function

def gcd(m,n):

If n is 0, return m

if n == 0:

 return m

If m is 0, return n

elif m == 0:

    return n

If otherwise, calculate the gcd recursively

else:

 return gcd(n,m%n)

To call the function to calculate the gcd of say 15 and 5 from main, use:

gcd(15,5)


Related Questions

3. Write a program to find the area of a triangle using functions. a. Write a function getData() for user to input the length and the perpendicular height of a triangle. No return statement for this function. b. Write a function trigArea() to calculate the area of a triangle. Return the area to the calling function. c. Write a function displayData() to print the length, height, and the area of a triangle ( use your print string) d. Write the main() function to call getData(), call trigArea() and call displayData().

Answers

Answer:

The program in C++ is as follows:

#include<iostream>

using namespace std;

void displayData(int height, int length, double Area){

   printf("Height: %d \n", height);

   printf("Length: %d \n", length);

printf("Area: %.2f \n", Area);

}

double trigArea(int height, int length){

double area = 0.5 * height * length;

   displayData(height,length,area);

   return area;

}

void getData(){

   int h,l;

   cin>>h>>l;

   trigArea(h,l);

}

int main(){

   getData();

   return 0;

}

Explanation:

See attachment for complete program where comments are used to explain the solution

Look at the code below and use the following comments to indicate the scope of the static variables or functions. Place the comment below the relevant line.

Module scope
Class scope
Function scope

#include
2
3 static const int MAX_SIZE=10;
4
5 // Return the max value
6 static double max(double d1)
7 {
8 static double lastMax = 0;
9 lastMax = (d1 > lastMax) ? d1 : lastMax;
10 return lastMax;
11 }
12
13 // Singleton class only one instance allowed
14 class Singleton
15 {
16 public:
17 static Singleton& getSingleton() { return theOne; }
18 // Returns the Singleton
19

Answers

Answer:

Explanation:

#include

static const int MAX_SIZE=10; //Class scope

// Return the max value

static double max(double d1) //Function scope

{

static double lastMax = 0;  //Function scope

lastMax = (d1 > lastMax) ? d1 : lastMax; //Function scope

return lastMax; //Module Scope

}

// Singleton class only one instance allowed

class Singleton  

{

public:

static Singleton& getSingleton()  //Function scope

{

return theOne; //Module Scope

}

// Returns the Singleton

Expain how central processing unit function? ​

Answers

Answer:

Answer of CPU

Explanation:

Central Processing Unit (CPU) consists of the following features − CPU is considered as the brain of the computer. CPU performs all types of data processing operations. It stores data, intermediate results, and instructions (program). It controls the operation of all parts of the computer.

Answer:

A central processing unit (CPU), also called a central processor, main processor or just processor, is the electronic circuitry that executes instructions comprising a computer program.

Is the ASSIGN statement a data entry statement, true or false?

Answers

I need the imagine to see so I will tell you the answer

Write a Python class that inputs a polynomial in standard algebraic notation and outputs the first derivative of that polynomial. Both the inputted polynomial and its derivative should be represented as strings.

Answers

Answer:Python code: This will work for equations that have "+" symbol .If you want to change the code to work for "-" also then change the code accordingly. import re def readEquation(eq): terms = eq.s

Explanation:

PLS HELP SO I CAN PASS WILL GIVE BRAINLINESS AND 30 POINTS
Charlie Chaplin is know for developing

a
The Dramedy
b
Early Special Effects
c
Slap-Stick
d
The Prat-Fall
Question 2 (1 point)
Chaplin felt it was important for the audience to

a
turn off their cellphones during the movie.
b
believe the stunts were real by doing them himself.
c
escape from their problems by avoiding difficult topics.
d
have an emotional connection with the characters.
Question 3 (3 points)
Match the silent film with its modern influence

Column A
1.
Metropolis:
Metropolis
2.
The Kid:
The Kid
3.
Nosferatu:
Nosferatu
Column B
a.Freddy Kruger
b.The Simpsons
c.Sharknado
d.Star Wars
Question 4 (1 point)
How did Nosferatu change the Vampire cannon (story)?

a
Vampires are friendly
b
Vampires can be killed by sunlight
c
Vampires can become invisible
d
Vampires can be repelled by garlic
Question 5 (1 point)
Metropolis was the first film to

a
have religious undertones.
b
use special effects.
c
have humanoid robots.
d
use Gothic Imagery.


movies being the kid , nosferatu , and metropolis

Answers

Answer:

a

have religious undertones.

b

use special effects.

c

have humanoid robots.

d

use Gothic Imagery.

Explanation:

To have a reason or purpose to do something

a
Motivate
b
Identity
c
Deceive
d
Anonymous

Answers

The answer is A. Motivate

Answer:

A

Explanation:

Which of the following are complete sets of data and are the rows of the table?
Files
Fields
Queries
Records

Answers

Answer:

I think the answer is going to be records

What is digital marketing?

Answers

Answer:

Digital marketing is the component of marketing that utilizes internet and online based digital technologies such as desktop computers, mobile phones and other digital media and platforms to promote products and services.

Explanation:

Create a public class called Exceptioner that provides one static method exceptionable. exceptionable accepts a single int as a parameter. You should assert that the int is between 0 and 3, inclusive.
If the int is 0, you should return an IllegalStateException. If it's 1, you should return a NullPointerException. If it's 2, you should return a ArithmeticException. And if it's 3, you should return a IllegalArgumentException.

Answers

Answer:

// Begin class declaration

public class Exceptioner {

   

   // Define the exceptionable method

   public static void exceptionable(int number){

      //check if number is 0.

       if(number == 0) {

           //if it is 0, return an IllegalStateException

           throw new IllegalStateException("number is 0");

       }

      //check if number is 1        

       else if(number == 1) {

           //if it is 1, return a NullPointerException

           throw new NullPointerException("number is 1");

       }

      //check if number is 2        

       else if(number == 2) {

           //if it is 2, return an ArithmeticException

           throw new ArithmeticException("number is 2");

       }

       

      //check if number is 3

       else if(number == 3) {

           //if it is 3, return an IllegalArgumentException

           throw new IllegalArgumentException("number is 3");

       }

   }

}

Sample Output:

Exception in thread "main" java.lang.ArithmeticException: number is 2                                                                          

       at Main.exceptionable(Main.java:26)                                                                                                    

       at Main.main(Main.java:36)  

Explanation:

The code is written in Java with comments explaining important parts of the code.

A sample output for the call of the method with number 2 is also provided. i.e

exception(2)

gives the output provided above.

Parts of a computer software

Answers

Answer:

I think application software

utility software

networking software

places where computer are used​

Answers

Answer:

Banks and financial.

Business.

Communication.

Defense and military.

Education.

Internet.

Medical.

Transportation.

etc..

Answer:

businesses, schools, colleges, medical offices, banks.

You plan to make a delicious meal and want to take the money you need to buy the ingredients. Fortunately you know in advance the price per pound of each ingredient as well as the exact amount you need. The program should read in the number of ingredients (up to a maximum of 10 ingredients), then for each ingredient the price per pound. Finally your program should read the weight necessary for the recipe (for each ingredient in the same order). Your program should calculate the total cost of these purchases, then display it with 6 decimal places.

Example There are 4 ingredients and they all have a different price per pound: 9.90, 5.50, 12.0, and 15.0. You must take 0.25 lbs of the first, 1.5 lbs of the second, 0.3 lbs of the third and 1 lb of the fourth. It will cost exactly $29.325000.

Answers

Answer:

In Python:

prices = []

pounds = []

print("Enter 0 to stop input")

for i in range(10):

   pr = float(input("P rice: "+str(i+1)+": "))

   pd = float(input("Pound: "+str(i+1)+": "))

   if pr != 0 and pd != 0:

       prices.append(pr)

       pounds.append(pd)

   else:

       break

amount = 0

for i in range(len(pounds)):

   amount+= (pounds[i]*prices[i])

print("Amount: $",amount)

Explanation:

These initialize the prices and pounds lists

prices = []

pounds = []

This prompts the user to enter up to 10 items of press 0 to quit

print("Enter 0 to stop input")

This iterates through all inputs

for i in range(10):

This gets the price of each item

   pr = float(input("P rice: "+str(i+1)+": "))

This gets the pound of each item

   pd = float(input("Pound: "+str(i+1)+": "))

If price and pound are not 0

   if pr != 0 and pd != 0:

The inputs are appended to their respective lists

       prices.append(pr)

       pounds.append(pd)

If otherwise, the loop is exited

   else:

       break

This initializes total to 0

amount = 0

This iterates through all inputs

for i in range(len(pounds)):

This multiplies each pound and each price and sum them up

   amount+= (pounds[i]*prices[i])

The total is then printed

print("Amount: $",amount)

What are some examples and non-examples of digital security?

Answers

Answer:

Devices such as a smart card-based USB token, the SIM card in your cell phone, the secure chip in your contactless payment card or an ePassport are digital security devices

What menu and grouping commands is the "SORT" tool? ( please answering meeeee)

A)Home - editing

B) Edit - format

C )Page layout - sheet options

D) File - edit

Answers

C, sorting is meant to arrange therefore layout falls under that

If you want to continue working on your web page the next day, what should you do?

a. Create a copy of the file and make changes in that new copy

b. Start over from scratch with a new file

c. Once a file has been saved, you cannot change it

d. Reopen the file in your text editor to

Answers

Answer:

d. Reopen the file in your text editor

Answer:

eeeeeeeee

Explanation:

The function below takes one parameter: an integer (begin). Complete the function so that it prints every other number starting at begin down to and including 0, each on a separate line. There are two recommended approaches for this: (1) use a for loop over a range statement with a negative step value, or (2) use a while loop, printing and decrementing the value each time.

1 - def countdown_trigger (begin):
2 i = begin
3 while i < 0:
4 print(i)
5 i -= 1 Restore original file

Answers

Answer:

Follows are code to the given question:

def countdown_trigger(begin):#defining a method countdown_trigger that accepts a parameter

   i = begin#defining variable that holds parameter value

   while i >= 0:#defining while loop that check i value greater than equal to0

       print(i)#print i value

       i -= 2  # decreasing i value by 2  

print(countdown_trigger(2))#calling method

Output:

2

0

None

Explanation:

In this code, a method "countdown_trigger" is declared, that accepts "begin" variable value in its parameters, and inside the method "i" declared, that holds parameters values.

By using a while loop, that checks "i" value which is greater than equal to 0, and prints "value" by decreasing a value by 2.

d) State any three (3) reasons why users attach speakers to their computer?​

Answers

Answer:

the purpose of speakers is to produce audio output that can be heard by the listener. Speakers are transducers that convert electromagnetic waves into sound waves. The speakers receive audio input from a device such as a computer or an audio receiver.

Explanation: Hope this helps!

Three reasons why users attach speakers to their computer

Answers

For media sound
For the game's multimedia sound
For essential system sound

If a system contains 1,000 disk drives, each of which has a 750,000- hour MTBF, which of the following best describes how often a drive failure will occur in that disk farm:

a. once per thousand years
b. once per century, once per decade
c. once per year, once per month
d. once per week
e. once per day
f. once per hour
g. once per minute
h. once per second

Answers

Answer:

once per month

Explanation:

The correct answer is - once per month

Reason -

Probability of 1 failure of 1000 hard disk = 750,000/1000 = 750 hrs

So,

750/24 = 31.25 days

⇒ approximately one in a month.

How should you present yourself online?

a
Don't think before you share or like something
b
Argue with other people online
c
Think before you post
d
Tag people in photos they may not like

hurry no scammers

Answers

C maybe ......,,,,.....

Answer: C) Think before you post.

Explanation:

There's a very good chance that whatever you post online will remain there indefinitely. So it's best to think about what would happen if you were to post a certain message on a public place. Keep in mind that you should also safeguard against your privacy as well.

what is the role of computer in modern problem solving​

Answers

Answer:

Una computadora es una herramienta muy básica para hacer tareas repetitivas de forma más eficiente. Una computadora no es capaz de analizar un problema y obtener una solución.

Explanation:

Write a program named HoursAndMinutes that declares a minutes variable to represent minutes worked on a job, and assign a value to it. Display the value in hours and minutes. For example, 197 minutes becomes 3 hours and 17 minutes.'

Answers

Answer:

Explanation:

The following code is written in Python, it asks the user for the number of minutes worked. Divides that into hours and minutes, saves the values into separate variables, and then prints the correct statement using those values. Output can be seen in the attached image below.

import math

 

class HoursAndMinutes:

   min = input("Enter number of minutes worked: ")

   hours = math.floor(int(min) / 60)

   minutes = (int(min) % 60)

   print(str(hours) + " hours and " + str(minutes) + " minutes")

your computer has been running slowly and you suspect it because its is low on memory. you review the hardware configuration and find that computer has only 4gb of ram. how can you determine how much memory your computer should have to run properly?​

Answers

By downloading software that is capable of checking live Ram usage/need. GIVE BRAINLIST

HURRY- I’ll give 15 points and brainliest answer!!
How do you insert text into a presentation??
By selecting text from the insert menu
By clicking in the task pane and entering text
By clicking in a placeholder and entering text
By drawing a text box clicking in it and entering text
(This answer is multiple select)

Answers

Answer:

the last one the drawing thingy:)))

You are responsible for a rail convoy of goods consisting of several boxcars. You start the train and after a few minutes you realize that some boxcars are overloaded and weigh too heavily on the rails while others are dangerously light. So you decide to stop the train and spread the weight more evenly so that all the boxcars have exactly the same weight (without changing the total weight). For that you write a program which helps you in the distribution of the weight.
Your program should first read the number of cars to be weighed (integer) followed by the weights of the cars (doubles). Then your program should calculate and display how much weight to add or subtract from each car such that every car has the same weight. The total weight of all of the cars should not change. These additions and subtractions of weights should be displayed with one decimal place. You may assume that there are no more than 50 boxcars.
Example 1
In this example, there are 5 boxcars with different weights summing to 110.0. The ouput shows that we are modifying all the boxcars so that they each carry a weight of 22.0 (which makes a total of 110.0 for the entire train). So we remove 18.0 for the first boxcar, we add 10.0 for the second, we add 2.0 for the third, etc.
Input
5
40.0
12.0
20.0
5. 33.
0
Output
- 18.0
10.0
2.0
17.0
-11.0

Answers

Answer:

The program in C++ is as follows:

#include <iostream>

#include <iomanip>

using namespace std;

int main(){

   int cars;

   cin>>cars;

   double weights[cars];

   double total = 0;

   for(int i = 0; i<cars;i++){

       cin>>weights[i];

       total+=weights[i];    }

   double avg = total/cars;

   for(int i = 0; i<cars;i++){

       cout<<fixed<<setprecision(1)<<avg-weights[i]<<endl;    }

   return 0;

}

Explanation:

This declares the number of cars as integers

   int cars;

This gets input for the number of cars

   cin>>cars;

This declares the weight of the cars as an array of double datatype

   double weights[cars];

This initializes the total weights to 0

   double total = 0;

This iterates through the number of cars

   for(int i = 0; i<cars;i++){

This gets input for each weight

       cin>>weights[i];

This adds up the total weight

       total+=weights[i];    }

This calculates the average weights

   double avg = total/cars;

This iterates through the number of cars

   for(int i = 0; i<cars;i++){

This prints how much weight to be added or subtracted

       cout<<fixed<<setprecision(1)<<avg-weights[i]<<endl;    }

Write a c++ to read seven days in an array and print it

Answers

Explanation:

Photosynthesis, the process by which green plants and certain other organisms transform light energy into chemical energy. During photosynthesis in green plants, light energy is captured and used to convert water, carbon dioxide, and minerals into oxygen and energy-rich organic compounds.

(The Person, Student, Employee, Faculty, and Staff classes) Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name, address, phone number, and email address.A student has a class status (freshman, sophomore, junior, or senior). Define the status as a constant. An employee has

Answers

Answer:

Explanation:

The following code is written in Java and creates all the classes as requested with their variables, and methods. Each extending to the Person class if needed. Due to technical difficulties I have attached the code as a txt file below, as well as a picture with the test output of calling the Staff class.

Setting Up Cascading Deletes
Use the drop-down menus to complete the steps to set up cascading deletes between two related tables.
1. Click the
tab
2. In the Relationships group, click Relationships
3. Double-click
4. In the Edit Relationship dialog box, add a check mark next to
5. Click OK
Done

Answers

Answer:

Database Tools, The Line Connecting the Tables, Cascade Delete Related Records

Explanation:

which of the following is an example of how to effectively avoid plagiarism

Answers

Answer:

You didn't list any choices, but in order to avoid all plagiarism, you must focus on rewriting the following script/paragraph in your own words. This could be anything from completely changing the paragraph (not the context) to summarizing the paragraph in your own words.

Answer:

Simon cites anything that he didnt know before he read it in any given source

Explanation:

a p e x

Other Questions
Pls help Im failing Jiro buys 2 rocks that each cost the same amount, r, and a magnifying glassthat costs $5. The total cost is $9. Model this situation with an equation and ahanger diagram.Pls help i will give brainly Repetition works best fora. Large, big picture conceptsb. Listsc.Small facts and vocabulary wordsd. The order of eventsPlease select the best answer from the choices provided 12. What is the energy released from respiration? A city government has all of the following responsibilities EXCEPT:a.maintaining the city and helping it growb.creating city rules and ordinancesc.offering and managing city public servicesd.managing a city court system Identify the structure of the human heart described as the main vessel in the arterial network that conveys oxygen-rich blood from the heart to all parts of the body except the lungs. Question 34 options: aorta atrium coronary artery pulmonary artery What is the percentage change from 5 to 8? What is an ionic solid? Can anyone help me with this? Government You are a financial adviser working with a client who wants to retire in eight years. The client has a savings account with a local bank that pays 8% annual interest. The client wants to deposit an amount that will provide her with $1,003,500 when she retires. Currently, she has $301,400 in the account. (FV of $1, PV of $1, FVA of $1, and PVA of $1) (Use the appropriate factor(s) from the tables provided.) How much additional money should she deposit now to provide her with $1,003,500 when she retires? (Round your answer to nearest whole dollar.) Find the lateral and surface area of a cone with an altitude of 5 and a slant height of 91/2 feet How is your body temperature held constant? Maurice fills a ball in the shape of a sphere with air. The diameter of the ball when it is filled is 24 inches. How much air, in cubic inches, is in the ball when it is filled? Solve in terms of like the example above.PLEASE HELP ME If a family has four children, determine the probability that exactly two of thechildren are girls Pls help I am getting timed I have 5 minutes left. Decrease 16855.21 by 13.5% Which letter corresponds to -3 ABCD the graph shows the solution to which system of inequalities? Jeff and Kathy are in a walking race. Kathy is faster and walks 3 meters per second. Jeff walks 2 meterper second. Jeff gets a 24 meter head start.At what time are Kathy and Jeff at the same distance in the race 1. 3 seconds 2. 30seconds 3. 36 seconds 4. 24 seconds Given that y varies inversely with x, if y=-5 when x=-6, find x when y=-2.5.