Explanation of Solution
Justification:
“No”, this
- 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...
Want to see the full answer?
Check out a sample textbook solutionChapter 1 Solutions
Programming Language Pragmatics, Fourth Edition
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education