Consider the following function that calculates x % y for positive integers x and y (that...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Consider the following function that calculates x % y for positive integers x and y (that is, x mod y, or the remainder when you take x and divide by y. 10 % 3 = 1). int mod (int x, int y) { int r = x; int k = 0; while (r = y) { r=r-y; k++; } return r; Find an appropriate loop invariant for the while loop of this function,. You do not need to prove the correctness of the loop invariant. Consider the following function that calculates x % y for positive integers x and y (that is, x mod y, or the remainder when you take x and divide by y. 10 % 3 = 1). int mod (int x, int y) { int r = x; int k = 0; while (r = y) { r=r-y; k++; } return r; Find an appropriate loop invariant for the while loop of this function,. You do not need to prove the correctness of the loop invariant.
Expert Answer:
Answer rating: 100% (QA)
The code provided is a simple function to calculate the modulus of two integers It repeatedly subtra... View the full answer
Related Book For
Computer Systems A Programmers Perspective
ISBN: 9781292101767
3rd Global Edition
Authors: Randal E. Bryant, David R. O'Hallaron
Posted Date:
Students also viewed these programming questions
-
List three specific parts of the Case Guide, Objectives and Strategy Section (See below) that you had the most difficulty understanding. Describe your current understanding of these parts. Provide...
-
Businesses use budgets to plan for the future. Thats what you will be doing for this assignment. Rather than budgeting for your current financial situation, I want you to put together a budget for...
-
Suppose the 2017 adidas financial statements contain the following selected data (in millions). Compute the following values and provide a brief interpretation of each. (a) Working capital. (b)...
-
Determine the deflection at midspan for the beam of Prob. 441 using Castiglianos theorem.
-
Graph y = e 2x and y = 5 together, and determine the xcoordinate of their point of intersection (to four decimal places). Express this number in terms of a logarithm.
-
What do current liabilities and current assets have in common? (a) Current assets are claims against current liabilities. (b) If current assets increase, then there will be a corresponding increase...
-
Under Section 11 of the Securities Act of 1933 and Section 10(b), Rule 10b-5, of the Securities Exchange Act of 1934, a CPA may be sued by a purchaser of registered securities. The following items...
-
What are company annual reports? A thorough report describing a company's activities over the past year. A way for a company to increase its stock price. A method for a company to track its...
-
Burnard (1992) sent a questionnaire to a stratified sample of nursing tutors and students in Wales, to study what the tutors and students understood by the term experiential learning. The population...
-
The demand for a monopolist's product: A. Is downward sloping.. B.Equals the market demand curve. C. Is equal to the firm's marginal revenue curve. D. All the statements are true. E. Answers (A) and...
-
A system can be "down" due to one or more issues, such as a server failure or a break in network communications. The recovery process when one or more failures occur is tied to the maximum tolerable...
-
Can you explain in details what it means. Newton developed the field of optics. If I wear glasses or contact lenses, I am using Newton's physical optics theories every day. Aside from glasses or...
-
Answered the question: 1) Explain the challenges the petrochemicals division of the oil company faced. 2) How did network optimization enable the company to reduce logistics costs?
-
Summary Momentary ventures, otherwise called attractive protections or impermanent speculations, are monetary speculations that can without much of a stretch be switched over completely to...
-
AAA just bought TTT using a stock deal. Before the merger AAA had 1,000 shares at a price of $150. TTT had 1,000 shares at a price of $50. The synergy value was 100,000. AAA gave 1 share of AAA for 4...
-
You have been employed as a customer relations representative for a firm. Your firm encourages the employees of customers to visit your firm's plant to see how products are made. One of your...
-
The water in tank A is at 270 F with quality of 10% and mass 1 lbm. It is connected to a piston/cylinder holding constant pressure of 40 psia initially with 1 lbm water at 700 F. The valve is opened,...
-
This problem concerns the m.o and swap.o modules from Figure 7.5. For each symbol that is defined or referenced in swap.o, indicate whether or not it will have a symbol table entry in the .symtab...
-
The functions intlen, len, and iptoa provide a very convoluted way to compute the number of decimal digits required to represent an integer. We will use this as a way to study some aspects of the gcc...
-
Let us analyze the relative performance of using conditional data transfers versus conditional control transfers for the programs you wrote for Problems 4.5 and 4.6. Assume that we are using these...
-
What is an off-by-one error?
-
Will the universality of management continue to be true in the future? Why or why not?
-
Describe what a manager does. How does the work of managers differ from that of nonmanagerial employees?
Study smarter with the SolutionInn App