// Not using conditional operator:
int gcd(int x, int y)
{
// Setup your vars:
int z; int retVal = -1;
// Figure out which is higher:
if (x > y) z = y
else z = x;
// Run the for loop:
// for (set the value; while this is true keep going; do this every iteration)
for (z; z > 0; z--)
{
if (x % z == 0 && y % z == 0)
{
// Set retVal to the z and z to 0 which ends the loop
retVal = z;
z = 0;
}
}
return retVal;
}
// Using conditional operator:
int gcd(int x, int y)
{
// Setup your vars:
int retVal = -1;
// Figure out which is higher:
// Conditional z equals x if (x > y) otherwise it equals y;
z = (x > y)?y:x;
// Run the for loop:
// for (set the value; while this is true keep going; do this every iteration)
for (z; z > 0; z--)
{
if (x % z == 0 && y % z == 0)
{
// Set retVal to the z and z to 0 which ends the loop
retVal = z;
z = 0;
}
}
return retVal;
}