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;
}
- All 3 functions return same value for all positive inputs
- f1 and f2 return same value for all positive inputs but not f3
- For some positive input all 3 functions return different values
- f2 and f3 return same value for all positive inputs but not f1