The gcd program of Example 1.20 might also be written int main() { int i = getint(),
Question:
The gcd program of Example 1.20 might also be written
int main() {
int i = getint(), j = getint();
while (i != j) {
if (i > j) i = i % j;
else j = j % i;
}
putint(i);
}
Does this program compute the same result? If not, can you fix it? Under what circumstances would you expect one or the other to be faster?
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 58% (12 reviews)
The difference between the two programs is in the two assignment statements i i j and j j i versus i ...View the full answer
Answered By
SUMAN DINDA
I LIKE TO TEACH STUDENTS. SO, I START MYSELF AS A PRIVATE TUTOR. I TEACH STUDENTS OF DIFFERENT CLASSES. I HAVE ALSO DONE BACHELOR OF EDUCATION DEGREE(B.ED). DURING THIS COURSE I HAD TO TEACH IN A SCHOOL. SO I HAVE A GOOD EXPERIENCE IN TEACHING.
5.00+
1+ Reviews
10+ Question Solved
Related Book For
Question Posted:
Students also viewed these Computer science questions
-
Expanding on Example 1.25, trace an interpretation of the gcd program on the inputs 12 and 8. Which syntax tree nodes are visited, in which order? Example 1.25 Many interpreters use an annotated...
-
Jim McNerney is racking up quite a record at 3M. Now, can he rev up its innovation machine? Jim McNerney was one of those boys: up early in the morning climbing trees while everybody else in the...
-
The Hartley (1946) and PolitzSimmons (1949) method. Suppose that all calls are made during Monday through Friday evenings. Each respondent is asked whether he or she was at home at the time of the...
-
Graph the exponential equation. Then state the inverse function in logarithmic form and graph it. Then state the domain and range of each function. = ()* = to Domain: Range: Inverse: Domain: Range:...
-
What is elaboration theory and how it would help you design a training program. ?
-
The following table shows a firms output, fixed cost, marginal costs, and marginal revenue. Do the values in this table indicate that the firm is a monopolist or part of a perfectly competitive...
-
Two parallel disks each of radius \(R\) are facing each other and separated by a distance \(H\). Derive an expression for the view factor between these disks.
-
Complete the following requirements regarding amortizing copyrights and trademarks: 1. Argyle Publishing Company purchased the copyright to a basic computer textbook for $40,000. The usual life of a...
-
Business tax senario: XYZ corporation made a profit of $ 5 0 0 , 0 0 0 . However, after business expenses and deductions, the taxable income is $ 3 0 0 , 0 0 0 . Calculate the corporation's tax...
-
Your brother has just started a new job as the Controller of an IESBA restricted audit client. You do not serve on the audit engagement. What steps must you take to ensure your independence is not...
-
Imperative languages like Fortran and C are typically compiled, while scripting languages, in which many issues cannot be settled until run time, are typically interpreted. Is interpretation simply...
-
Both interpretation and code generation can be performed by traversal of a syntax tree. Compare these two kinds of traversals. In what ways are they similar/different?
-
If you borrow $50,000 today at 10% interest for eight years. How much of your first payment will be applied towards the principal of the loan? (Points: 3) a. $5,000 b. $4,372 c. $4,790 d. Zero, all...
-
What methodologies are employed to transform abstract goals into concrete, actionable steps in project management ?
-
1. Assume the expected return on the market portfolio is 15.0% with volatility of 12.8%. The risk-free rate is 4%. a) What is the market portfolio's Sharpe ratio? b) What is the slope of the CML? c) ...
-
Describe Protection of depositor's funds in the US, UK and Bahamas.
-
1.Assume a company had sales for the past two years of 5,300,000 in 2010 and 5,830,000 in 2011, what yearly sales budget would be set if the same sales increase were applied when setting the budget...
-
How does the artwork "The battle about money" by Pieter van der Heyden relates to finance? Link to artwork: https://www.metmuseum.org/art/collection/search/338702
-
Using the information from Exercise 16-6, calculate the balance in the Investment in Minecraft Ltd. Common Shares account. Assume that after all the above transactions took place, Kinross sold its...
-
The cost curve for the city water supply is C(Q) = 16 + 1/4 Q2, where Q is the amount of water supplied and C(Q) is the cost of providing Q acre-feet of water. (An acre-foot is the amount of water...
-
True or False? All recursive algorithms need a base case, even if it is Do nothing.
-
Design a maze in which there are starting positions that return Trapped when the starting position is Open.
-
True or false? If false, correct the statement. A recursive solution should be used when: 1. computing time is critical. 2. the nonrecursive solution would be longer and more difficult to write. 3....
-
Implement the definition of the function rotate ToLeft(), member of the DArray class, so that it rotates all the elements of the array object to the left by one position. Example: [6, 2, 5, 3] [2, 5,...
-
Write the definition of the of the function is Full() as a member function of the DArray class. The function returns true if the array is full, or false otherwise. Functions.cpp 1 #include "DArray.h"...
-
Write a program that will calculate the trajectory of a golf ball thrown with a velocity of 25.6 m/s at an angle of 0 = 35 relative to the horizontal, from a hill that is 2.1 meters above the ground...
Study smarter with the SolutionInn App