Consider the following piece of C programming code:int x=128, y=110;
do
{
if(x>y)
x=x-y;
else
y=y-x;
} while(x!=y);
printf("%d",x);Which one will be the output?
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: B. 2
Explanation
This is Euclid's subtraction method, so it prints gcd(128, 110). 128 − 110 = 18; then y reduces 110 → 92 → 74 → 56 → 38 → 20 → 2; then x reduces 18 → 16 → … → 2. When x = y = 2 the loop stops. Output: 2.More Programming Languages and Computer Graphics questions
- Match List I with List IIList I List II A. Overloading I. Since function call is resolved during run time, the execution is slow. B. Early…
- Consider the following statements for XML (Extensible Markup Language): A. The number of tags decreases and users can define their own tags…
- Match List I with List IIList I List II A. Oblique Projection I. When the direction of projection is so chosen that the lines perpendicular…
- What will be the output of the following C programming code:void main() { int *i, a=12, b=2, c; c = (a=a+b, b=a/b, a=a*b, b=a-b); i = &c; p…
- Only legal pointer operations: A. pointer + number → pointer B. pointer − number → number C. pointer + pointer → pointer D. pointer − point…
- Consider the operators used in C Programming given below: A. && B. += C. >> D. >= E. ?: Choose the correct order of precedence of the opera…