54 votes 54 votes Consider the following pseudo code, where $x$ and $y$ are positive integers. begin q := 0 r := x while r ≥ y do begin r := r - y q := q + 1 end end The post condition that needs to be satisfied after the program terminates is $\{ r = qx + y \wedge r < y\}$ $\{ x = qy + r \wedge r < y\}$ $\{ y = qx + r \wedge 0 < r < y\}$ $\{ q + 1 < r - y \wedge y > 0\}$ Programming in C gatecse-2015-set1 programming loop-invariants normal + – makhdoom ghaya asked Feb 13, 2015 • edited Jan 15, 2018 by kenzou makhdoom ghaya 15.7k views answer comment Share Follow See all 3 Comments See all 3 3 Comments reply saurav raghaw commented Sep 9, 2018 reply Follow Share https://gateoverflow.in/118381/gate2017-2-37 1 votes 1 votes Ray Tomlinson commented Jan 17 i edited by Ray Tomlinson Jan 17 reply Follow Share “ ^ “ is EXOR operator in C language.take y =2 x= 11 and simply you get option B as answer 0 votes 0 votes himanshud2611 commented Jan 28 reply Follow Share Concept in Loop Invariant Problems: Just take arbitrary values of variables, here x and y as q is already given (0) and perform operations in while loop. Satisfy the options with the updated values of variables. 0 votes 0 votes Please log in or register to add a comment.
1 votes 1 votes r is remainder, y is the one dividing x and q is the result. So, look for this : x = qy + r P.S: Not standard method. ShamikBanerjee answered Feb 19, 2019 ShamikBanerjee comment Share Follow See all 0 reply Please log in or register to add a comment.
1 votes 1 votes 1. Loop will terminate when r<y 2. Every iteration updates r as r-y. So the loop iterates r/y times. 'r=x' is given. So we get x/y i.e x get divided by y. Hence, x=qy+r would be the second condition. So, answer would by option B TheAnteamatter answered Jun 24, 2020 TheAnteamatter comment Share Follow See all 0 reply Please log in or register to add a comment.
0 votes 0 votes the pseudo code divides $x$ with $y$ leaving remainder $r$ upto the point when remainder i.e $r<y$ as $Dividend= Divisor*Quotient +Remainder$ and $remainder < divisor$ x=qy+r and r<y option B Musa answered Oct 13, 2020 Musa comment Share Follow See all 0 reply Please log in or register to add a comment.