recategorized
845 views
1 votes
1 votes

Assume that $x$ and $y$ are non-zero positive integers. What does the following program segment perform?

while (x!=0)
{
if(x>y)
x=x-y;
else y=y-x;
printf(“%d”, x)
}
  1. Computes LCM of two numbers
  2. Computes GCD of two numbers
  3. Divides large number with small number
  4. Subtracts smaller number from larger number
recategorized

1 Answer

0 votes
0 votes

The code has many syntax errors.

eg: int is written in place of if

By analysing logic it seems like it computes GCD of two numbers!

Answer:

Related questions

1 votes
1 votes
3 answers
1
go_editor asked Jul 21, 2016
2,628 views
Consider the following program segment:d=0; for(i=1; i<31, ++i) for (j=1; j < 31; ++j) for (k=1; k < 31; ++k) if((i+j+k%3)==0)) d=d+1; printf(“%d”, d);The output will...
1 votes
1 votes
1 answer
2
go_editor asked Jul 21, 2016
1,724 views
What is the output of the following program segment?sum(n) { if (n<1) return n; else return (n+sum(n-1)); } main() { printf(&ldquo;%d&rdquo;, sum(5)); }10161514
1 votes
1 votes
2 answers
3
go_editor asked Jul 21, 2016
3,682 views
What is the size of the following union? Assume that the size of int=2, size of float =4, size of char=1union tag { int a; float b; char c; };2417