edited by
2,454 views
5 votes
5 votes

Consider the following C functions:

int f1(int a, int b)
{
	while (a != b)
	{
		if(a > b)
			a = a - b;
		else
			b = b - a;
	}
	return a;
}
int f2(int a, int b)
{
	while (b != 0)
	{
		int t = b;
		b = a % b;
		a = t;
	}
	return a;
}
int f3(int a, int b)
{
	while (a != 0)
	{
		int t = a;
		a = b % a;
		b = t;
	}
	return b;
}
  1. All 3 functions return same value for all positive inputs
  2. f1 and f2 return same value for all positive inputs but not f3
  3. For some positive input all 3 functions return different values
  4. f2 and f3 return same value for all positive inputs but not f1
edited by

3 Answers

Best answer
6 votes
6 votes
All three functions are same.
Function calculates GCD of numbers 'a' and 'b'.
selected by
Answer:

Related questions

3 votes
3 votes
2 answers
3
8 votes
8 votes
2 answers
4