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
Who plays rocket league?
Rashid [163]

Answer:

I dont

Explanation:

8 0
3 years ago
Read 2 more answers
What does altgr mean on a keyboard.
Setler [38]
AltGr (also Alt Graph) is a modifier key found on many computer keyboards (rather than a second Alt key found on US keyboards). It is primarily used to type characters that are not widely used in the territory where sold, such as foreign currency symbols, typographic marks and accented letters.
8 0
3 years ago
Need help plzz now it's hard ​
nalin [4]

Answer:

tost makinasıyla mı çektin amk bide siz zenginsizniz

Explanation:

5 0
3 years ago
Communication between a computer and a keyboard involves ______________ transmission.
4vir4ik [10]

Answer:

Simplex transmission

Explanation:

Communication between computer and keyboard involves which transmission? Answer: Simplex transmission requires communicating between a computer and a keyboard. The simple transmission & communication channel allows data from only one direction.

8 0
2 years ago
Compare physical storage and virtual storage. Give an example of each and explain why one type allows computers to access data a
Nuetrik [128]
Physical storage is like your Hard Drive, Virtual is what is called the Cloud. Hard drives are able to pull information directly from inside the computer while the cloud has to do over the internet.
8 0
4 years ago
Other questions:
  • An electronic resume is a plain-looking document. True of False?
    6·2 answers
  • What was Leonardo da Vinci an expert in
    11·1 answer
  • Which of the following functions sends the the GPA entered by the user to the calling function? A. def get_gpa(): gpa = float(in
    8·1 answer
  • How long Will it take me to master scada and plc programming?​
    9·1 answer
  • Write a program that accepts a file name from the command line, then initializes an array with test data using that text file as
    6·1 answer
  • You can invoke or call a method from another program or method. When methods must share data, you can pass the data into and ret
    6·1 answer
  • A cubit is an ancient unit of length, roughly the distance between one’s fingers and elbow. The definition of one cubit is 18 in
    12·1 answer
  • Assume that programs spend about 25% of their time waiting for I/O operations to complete. If there are FOUR programs loaded int
    9·1 answer
  • you are a bank loan officer. carter has to come into your office and applied for a loan for a car.you ran his credit report, and
    7·1 answer
  • :) :) :):):):)):):):)):)/):))::)):):):):):)):):)):):))/):):))
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!