/* gcd.c  P. Conrad for CISC105 Fall 2005 */

#include <stdio.h>

/* A stub function for greatest common divisor; 
   finish it then TAKE OUT THIS COMMENT!!!! */

int gcd(int num1, int num2)
{
  int remainder;

  /* Convert num1 and num2 to their absolute values */

  /* You can use an if, and if/else, a ternary operator
     or a library function; if you use a library function,
     be sure to use one that works on int, not float
     or double! @@@ */

  /*  num1 = ... ? @@@ */
  /*  num2 = ... ? @@@ */

  /* Use a do while loop to repeatedly carry
     out some steps until the remainder is zero */

  do {

    
    /* @@@ carry out the algorithm described in the textbook
       on pages 273-274 */

    remainder = 0; /* take out this line of code! */
    
  } while (remainder != 0);

  return 999; /* this is a fake value so the code compiles;
		 but the code won't pass the test!  Take
		 this out in your final version @@@ */

}

void testGcd(int x, int y, int answer)
{
  int returnValue;

  /* message to the user that test is underway... */

  printf("Testing x=%d y=%d answer should be=%d\n", x,y,answer);

  /* try the function */
  returnValue = gcd(x,y);

  /* report the result */

  if (returnValue == answer)
    printf("... passed the test!\n");
  else
    printf("... failed the test! returnValue was: %d\n",
	   returnValue);
}

int main(void)
{

  /* print a message to the user */

  printf("This main program tests our gcd function.\n");

  testGcd(5, 10, 5);
  testGcd(42, 56, 14);  
  testGcd(-252, 735, 21);  
  testGcd(252, -735, 21);  
  testGcd(252, 735, 21);  
  testGcd(-252, -735, 21);
  testGcd(735, 252, 21);  

  printf("Testing complete!\n");

  return 0;

}


