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
kirza4 [7]
4 years ago
7

Write a program that applies the Euclidean algorithm to find the greatest common divisor of two integers. Input should be two in

tegers a and b and output should be the greatest common divisor of a and b. Test your program with several examples using both positive and negative values for a and b.
Computers and Technology
1 answer:
laila [671]4 years ago
6 0

Answer:

// here is code in c++.

#include <bits/stdc++.h>

using namespace std;

// function that return greatest common divisor

int g_c_d(int num1, int num2)

{

if (num1 == 0)

 return num2;

return g_c_d(num2 % num1, num1);

}

// main function

int main()

{

// variables

int num1,num2;

cout<<"enter two numbers:";

// read two numbers from user

cin>>num1>>num2;

// call the function and print the gcd of both

cout<<"greatest common divisor of "<<num1<<" and "<<num2<<" is "<<g_c_d(num1.num2)<<endl;

}

Explanation:

Read two numbers from user and assign them to variables "num1" and "num2".Call the function g_c_d() with parameter "num1" and "num2".According to Euclidean algorithm, if we subtract smaller number from the larger one the gcd will not change.Keep subtracting the smaller one then we find the gcd of both the numbers.So the function g_c_d() will return the gcd of both the numbers.

Output:

enter two numbers:5 9

greatest common divisor of 5 and 9 is 1

enter two numbers:-25 15

greatest common divisor of -25 and 15 is 5

You might be interested in
I NEED HELP!!! BRAINLIEST!!!
Trava [24]

Answer:

DHCP Dynamic Host Configuration Protocol:

Is a network service that automatically assigns IP addresses and other TCP/IP configuration information on network nodes configured as DHCP clients. Server allocates IP addresses to DHCP clients dynamically. Should be configured with at least one DHCP scope. Scope contains a range of IP addresses and a subnet mask, and can contain other options, such as a default gateway and Domain Name System. Scope also needs to specify the duration of the lease and usage of an IP affects after which the node needs to renew the lease with the SHCP server. Determines the duration, which can be set for a defined time period or for an unlimited length of time.

DNS Domain Name Service: Is a TCP/IP name resolution service that translates FQDNs into IP addresses. System of hierarchical databases that are stored on separate DNS servers on all networks that connect to the Internet. DNS servers store, maintains and update databases, they respond to DNS client name resolution requests to translate host names into IP addresses.

DNS Components

DNS database is divided logically into a heieratchical grouping of domains. Physically into files called zones. Zone files contain the actual IP-to-host name mapping for one or more domains. Zone files is stored on the DNS server that is responsible for resolving hot names for the domains contained in the zone. Each network node in that domain will have a host record within the domain's zone files. Includes the node's host name, FQDN, and assigned IP address.

DNS Servers

*If you are configuring static IP addresses, including the IP address of the default DNS servers as you configure each client.

*If you are using DHCP, use the DHCP scope options to specify the IP Explanation:

3 0
3 years ago
Read 2 more answers
Explain what mistake Miranda made in the following scenario. Situation: Miranda suspects that there may be a problem with the ha
Dennis_Churaev [7]

Answer: Answer below.

Explanation:

I'm not fully sure myself, so don't agree with me fully.

I believe what she may have done wrong is tell the technician about a "program." A program doesn't have to do anything with physical hardware.

5 0
3 years ago
Read 2 more answers
I know this isn't a school question but it is important! how do I get out of hp hardware diagnostics UEFI on hp pc? (step by ste
Debora [2.8K]

Answer:

1. Turn off the computer and wait five seconds.

2. Press the Power button to start the computer and repeatedly press the F10 key to enter the BIOS setup menu.

3. On the BIOS Setup screen, press F9 to select and load the BIOS Setup Default settings.

4. Press F10 to Save and Exit.

5. Use the arrow keys to select Yes, then press Enter when asked Exit Saving Changes?

6. Follow the prompts to restart your computer.

After you have get to the operating system,

1. Press CTRL + Alt + Del on the blank screen.

2. Click on Task Manager

3. Click "File" - "Run a new task" If there is no "file" option, please click on the task manager under the "details"

4. In the pop-up window, enter "msconfig" click "OK"

5. In the system configuration window that appears, click "Service" and uncheck "App Readiness".

6. Click "Apply" --- "OK"

7. In the following window appears to click on the "restart"

6 0
3 years ago
1. Create an interface called Runner. The interface has an abstract method called run() that display a message describing the me
Colt1911 [192]

Answer:

see explaination for program code

Explanation:

interface Runner

{

public abstract void run();

}

class Machine implements Runner

{

public void run()

{

System.out.println("Machine is running");

}

}

class Athlete implements Runner

{

public void run()

{

System.out.println("Athlete is running");

}

}

class PoliticalCandidate implements Runner

{

public void run()

{

System.out.println("Political Candidate is running");

}

}

class DemoRunners

{

public static void main (String[] args)

{

Machine m = new Machine();

m.run();

Athlete a = new Athlete();

a.run();

PoliticalCandidate pc = new PoliticalCandidate();

pc.run();

}

}

7 0
4 years ago
ou have a company network that is connected to the internet. You want all users to have internet access, but you need to protect
Rus_ich [418]

Server and network is 2 different things, just put the server on a different network.  ;) duh

Explanation:

4 0
3 years ago
Other questions:
  • What’s the answer?............................
    13·1 answer
  • In Microsoft Windows, which of the following typically happens by default when a file is "double-clicked"
    10·2 answers
  • What field in an IPv4 packet is altered to prioritize video streaming traffic over web surfing traffic?
    7·1 answer
  • What does this result prove about the computer’s network connectivity?
    12·1 answer
  • Waygate's residential Internet modem works well but is sensitive to power-line fluctuations. On average, this product hangs up a
    6·1 answer
  • Help plz,l didn’t pay attention in class
    7·1 answer
  • What will the following code display?
    12·1 answer
  • I don’t understand this, i need help
    7·1 answer
  • Why is it better for a CPU to have more than one cache?
    6·2 answers
  • Is Using programming libraries is one way of incorporating existing code into new programs true
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!