...
Programming
October 17, 2023
Logic-Gates
October 18, 2023
Programming
October 17, 2023
Logic-Gates
October 18, 2023

Programming

Question 31

Consider the following program fragment for reversing the digits in a given integer to obtain a new integer. Let n = d1d2…dm.

     int n, rev;
     rev = 0;
     while (n > 0)
     {
        rev = rev*10 + n%10;
        n = n/10;
     }

The loop invariant condition at the end of the ith iteration is:

A
n = d1d2…dm-i and rev = dmdm-1…dm-i+1
B
n = dm-i+1…dm-1dm or rev = dm-i…d2d1
C
n ≠ rev
D
n = d1d2…dm and rev = dm…d2d1
Question 31 Explanation: 
In each iteration the right most digit of n is going to make to the right end of the reverse.
Correct Answer: A
Question 31 Explanation: 
In each iteration the right most digit of n is going to make to the right end of the reverse.
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
error: Alert: Content selection is disabled!!