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
Create your code from the story using code blocks.You must include at least one of each of the following blocks. You can draw or
Mazyrski [523]

Answer:

Como puedo hacerlo.

Explanation:

Me enseñas como hacerlo

6 0
3 years ago
Read 2 more answers
25 POINTS!!!!!!!!!!!!!
siniylev [52]

Answer:

im pretty sure its digital footprint

Explanation:

3 0
3 years ago
What name is given to the assurance that requested information is available to authorized users upon request
mrs_skeptik [129]

Answer:

Availability

Explanation:

With Data availability, it means that we are saying that information is accessible to users. This gives the assurance of the system and also the data being accessible to authenticated users anytime they have the need for it.

It is simply saying that information would be operable by users with authorization whenever they request to.

5 0
3 years ago
Which of the following data structures can erase from its beginning or its end in O(1) time?
jekas [21]

Where all "the following" i can help you but you said which of the folllowing and ther no picture or anything?

3 0
3 years ago
A local area network using internet-based protocols is an:
Virty [35]
An Xfinity store/business. They are the perfect example.
I hope this helps! :)
4 0
3 years ago
Other questions:
  • Write a script that will generate random integers in the range from
    10·1 answer
  • Assume that an int variable age has been declared and already given a value and assume that a char variable choice has been decl
    9·1 answer
  • When you choose the ____ compression setting, photos are compressed to the resolution specified on the advanced tab in the power
    13·2 answers
  • How can touch typing quickly but accurately improve your earnings (the money you can make)
    15·2 answers
  • You’re responding to a troubleshooting ticket about a laser printer in HR that isn’t working. According to reports, the printer
    7·1 answer
  • A person who has a been exposed to technology at a young age is?
    8·1 answer
  • Friedman (1999) argues that "we are wrong to base health promotion in all societies on a Western framework for human development
    11·1 answer
  • M
    15·1 answer
  • A type of SDLC in which each phase has results that flow into the next phase is called the __________ model.
    8·1 answer
  • There are 2048bytes in4megabytes true or false​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!