/*--------------------------------------------------------------------*/ /* testintmath.c (Version 4) */ /* Author: Bob Dondero */ /*--------------------------------------------------------------------*/ #include "intmath.h" #include #include /*--------------------------------------------------------------------*/ /* Read two positive integers from stdin. Return EXIT_FAILURE if stdin contains bad data. Otherwise compute the greatest common divisor and least common multiple of the two positive integers, write those two values to stdout, and return 0. */ int main(void) { int i1; int i2; int iGcd; int iLcm; int iScanfReturn; printf("Enter the first positive integer:\n"); iScanfReturn = scanf("%d", &i1); if ((iScanfReturn != 1) || (i1 <= 0)) { fprintf(stderr, "Error: Not a positive integer.\n"); exit(EXIT_FAILURE); } printf("Enter the second positive integer:\n"); iScanfReturn = scanf("%d", &i2); if ((iScanfReturn != 1) || (i2 <= 0)) { fprintf(stderr, "Error: Not a positive integer.\n"); exit(EXIT_FAILURE); } iGcd = IntMath_gcd(i1, i2); iLcm = IntMath_lcm(i1, i2); printf("The greatest common divisor of %d and %d is %d.\n", i1, i2, iGcd); printf("The least common multiple of %d and %d is %d.\n", i1, i2, iLcm); return 0; }