Programming Language Pragmatics, Fourth Edition
Programming Language Pragmatics, Fourth Edition
4th Edition
ISBN: 9780124104099
Author: Michael L. Scott
Publisher: Elsevier Science
Expert Solution & Answer
Book Icon
Chapter 1, Problem 4E

Explanation of Solution

Justification:

“No”, this program does not compute the same result.

  • The variation between the two programs is with the assignments statements in each program.
  • The “Example 1.20” uses “i=i-j” and “j=j-i” but in the given program the assignment statement is represented as “i=i%j” and “j=j%i”.
  • Suppose “i>j”, then “i == i-(j*(i/j))”, here the slash (/) indicates integer division...

Explanation of Solution

The solution for the given program:

  • The following program fix the problems in the given program.

        //Defining the main function.

        int main()

        {

/*Getting the input of i and j using getint() function.*/

            int i = getint(), j = getint();

            //Checking the condition for i and j.

            if (i < j)

             {

/*Storing the j value to the temporary value.*/

                int t = j;

                //Swapping the value i and j.

                j = i;

    /*Storing the temporary value to the i value.*/

                i = t;

            }

            //Checking for the j value.

            while (j != 0)

            {

                //Assigning the j to temporary value.

                int t = j;

    /* Getting the i using computation of i%j. */

                i = i % j;

/* Storing the temporary value to the j. */

                j = t;

            }

            //Printing the i using putint() function...

Explanation of Solution

Situations in which the programs gives the faster result:

  • The value of “i and j” are in the same magnitude, the original subtraction based program may produce the faster output...

Blurred answer
Students have asked these similar questions
C. Homework Assignment Task: Write a one-page CV using the provided template. Steps: 1. Use the CV guide to structure your CV. 2. Fill in each section with real information about yourself. 3. Format your CV neatly and use professional language. 4. Submit to the instructor before the next class
Simulate on a vertical time axis (with events labeled with the senders names A-D) the contention period of FOUR equally distanced Ethernet stations that all attempt to transmit at T=0 a minimally sized frame, in the style of the binary Exponential Backoff Algorithm. Assume that time is measured in slot times, and that exactly one slot time is needed to detect a collision (so that if two stations transmit at T=1 and collide, and one of them chooses a backoff time k=0, then that station will transmit again at T=2). Use as coin flip (source of randomness) an ID written in binary. use the bits in order from the least significant to the most significant. If for a given coin throw you need k bits, use the least significant ID bit extracted in the corresponding group of bits, as the least significant bit of the coin thrown. Start be writing the ID, which is 904012207 As example of the expected answer format,  with the random sequence R:   100101010101001011001010 01 01011  10010 1010 1010 010…
Big State University The Big State University course catalog reads as follows: "To enroll in MIS 260, which is an advanced course, a student must complete two prerequisites: MIS 120 and MIS 222. A student who completes either one of these prerequisites and obtains the instructor's permission, however, will be allowed to take MIS 260." Tasks 1. Create a decision table that describes the Big State University course catalog regarding eligibility for MIS 260. Show all possible rules. 2. Simplify the table you just created. Describe the results. 3. Draw a simplified decision tree to represent the Big State University catalog. Describe the results. 4. Why might you use a decision tree rather than a decision table?
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education