Computer Science, asked by blackfalacon, 11 months ago

The following function is a part of some class which computes and returns the
greatest common divisor of any two numbers. There are some places in the code
marked by ?1?, ?2?, ?3?, ?4?, ?5? which must be replaced by statement/expression
so that the function works correctly.

int gcd(int a, int b)
{
int r;
while(?1?)
{
r=?2?;
b=?3?;
a=?4?;
}
if (a==0)
return ?5?;
else
return -1;
}
(i) What is the expression or statement at ?1?.
(ii) What is the expression or statement at ?2?.
(iii) What is the expression or statement at ?3?.
(iv) What is the expression or statement at ?4?.
(v) What is the expression or statement at ?5?.

Answers

Answered by jhansi256
6

Explanation:

1- expression

2- expression

3- statement

4- statement

5-expression

Attachments:
Answered by lovingheart
5

Answer:

(i) b!=0   ii) r= b    iii) b = a%b   iv) a = r   v) return 1

Explanation:

In this program, the two numbers are passed to the gcd(). GCD is found using while loop. While loop runs, until b is 0. The numbers are swapped to find the “GCD”. b is assigned to the temporary variable “r” then b is replaced with “a%b” and then the value of “r is assigned to a”.

Finally if the value of a is zero then it returns 1 otherwise it returns -1.

Similar questions