subject

The greatest common divisor (gcd) of two positive integers is the largest integer that divides evenly into both of them. for example, the gcd (102, 68) = 34. we can efficiently compute the gcd using the following property, which holds for positive integers p and q: if p > q, the gcd of p and q is the same as the gcd of q and p % q. in euclid's algorithm, we start with two numbers x and y. if y is zero then greatest common divisor of both will be x, but if y is not zero then we assign the y to x and y becomes x%y. once again we check if y is zero, if yes then we have our greatest common divisor or gcd otherwise we keep continue like this until y becomes zero. since we are using modulo operator, the number is getting smaller and smaller at each iteration, so the x%y will eventually become zero. let' take an example of calculating gcd of 54 and 24 using euclid's algorithm. here x = 54 and y = 24, since y is not zero we move to the logical part and assign x y, which means x becomes 24 and y becomes 54%24 i. e. 6. since y is still not zero, we again apply the logic. this times x will become 6 and y will become 24%6 i. e. y = 0 bingo, y is now zero which means we have our answer and it's nothing but the value of x which is 6 (six). write a recursive java program to calculate the gcd by euclid's method.

ansver
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 20:00, Jana1517
What is the worst-case complexity of the maxrepeats function? assume that the longest string in the names array is at most 25 characters wide (i. e., string comparison can be treated as o( class namecounter { private: int* counts; int nc; string* names; int nn; public: namecounter (int ncounts, int nnames); int maxrepeats() const; }; int namecounter: : maxrepeats () { int maxcount = 0; for (int i = 0; i < nc; ++i) { int count = 1; for (int j = i+1; j < nc; ++j) { if (names[i] == names[j]) ++count; } maxcount = max(count, maxcount); } return maxcount; }
Answers: 3
image
Computers and Technology, 23.06.2019 17:00, solizpaco7124
1. which of the following is not an example of an objective question? a. multiple choice. b. essay. c. true/false. d. matching 2. why is it important to recognize the key word in the essay question? a. it will provide the answer to the essay. b. it will show you a friend's answer. c. it will provide you time to look for the answer. d. it will guide you on which kind of answer is required.
Answers: 1
image
Computers and Technology, 24.06.2019 01:30, jadaroyval
Write a program that asks the user to enter the name of an input file. if the file does not exist, the program should prompt the user to enter the file name again. if the user types quit in any uppercase/lowercase combinations, then the program should exit without any further output.
Answers: 3
image
Computers and Technology, 24.06.2019 09:30, nialphonsa
Atype of researcher who uses computers to make sense of complex digital data
Answers: 1
You know the right answer?
The greatest common divisor (gcd) of two positive integers is the largest integer that divides evenl...

Questions in other subjects: