The greatest common divisor (GCD) of two integers is the product of the integer’s common factors. Write a program that reads two numbers and uses functions
int gcd(int firstNum,
int secondNum);
void
minmax((int firstNum, int secondNum,
int *maxNum, int *minNum);
to determine the greatest common divisor maximum and minimum
of firstNum and secondNum. The program should produce the output
shown below
This program calculate the minimum and gcd of two integers
Enter the first integer: 45
Enter the second integer: -21
The minimum of 45 and -23 is -21
The gcd of 45 and
-21 is 3
The algorithm to calculate the gcd is
1. Take the absolute values of the two numbers, call the firstNumA and secondNumA
2. Divide the secondNumA by the firstNumA and find remainderOld
3. If the remainderOld is zero the first number is the gcd. You are done
4. Otherwise, Divide the first number by the remainder, find remainderNew
5. If the remainderNew is zero then remainderOld is the gcd. You are done
6. Otherwise, divide remainderOld by the remainderNew to get remainderNewest
7. If remainderNewest is 0 then the remainderNewj is the gcd. You are done
8. Otherwise, remainderOld=remainderNew, then remainderNew=remainderNewest, then go to step 5
If you want more practice try some of the end of chapter problems in your textbook.