/*============================================================================*//* badprog.c: *//* This program is designed to show how error messages work on C. The *//* important techniques learned from this exercise will help students later *//* when correcting programs. *//* Author: Amanda Higgins ENG 17O *//* Lecture Section: 1 Exercise #3 *//* Teaching Assistant: John Canby Due: 09 20 2006 *//*============================================================================*/ #include <stdio.h> #include <stdlib.h> /* this is for the abs() functon */ #include <limits.h> /* this is for INT_MAX */ #define ZRO 0 #define TRUE 1 #define FALSE 0 typedef int LOGICAL; void getinput(int* num1, int* num2); void showrslt(int num1, int num2);int main(void) /* start main funtion */{ int num1, num2;/* getinput(&num1, &num2); /*call the input function *//* showrslt(num1, num2); /* call the calculating function */ return 0;} /* end main *//* getinput(num1, num2): read numbers from another directory to use in later *//* calculation. */void getinput(int* num1, int* num2){ LOGICAL badnbr; fprintf(stdout, "Enter an integer >"); fscanf(stdin, "%d", num1); if (*num1 == ZRO) { badnbr = TRUE; /* make badnbr = true because of zero*/ while (badnbr) { fprintf(stdout, "Enter a non-zero integer >"); fscanf(stdin, "%d", num2); if (*num2 != ZRO) /* test it and make sure its ok*/ badnbr = FALSE; else fprintf(stdout, "%d", "is not acceptable/n", *num2); } } else { fprintf(stdout, "Enter another integer >"); fscanf(stdin, "%d", num2); } return; } /* ends getinput *//* showrslt(num1, num2): print out solutions to the calculations done. */void showrslt(int num1, int num2){ /* start of showrslt */ int remainder, divdnd, divsr, prelim, smallest; divdnd = abs(num1); /* initialize divnd */ divsr = abs(num2); /* initisalse divsr */ if (divsr == ZRO) divsr = divdnd; else { remainder = divdnd % divsr; while (remainder > 0) { divdnd = divsr; divsr = remainder; remainder = divdnd % divsr; } } fprintf(stdout, "The greatest common divisor of %d and %d is %d/n", num1, num2, divsr); if (abs(num1) > abs(num2)) { prelim = abs(num1 / divsr); smallest = num2; } else { prelim = abs(num2 / divsr); smallest = num1; } fprintf(stdout, "The least common multiple of %d and %d", num1, num2); if (INT_MAX / prelim >= smallest) fprintf(stdout, "is %d\n", prelim * smallest); else fprintf(stdout, "is larger than d\n", INT_MAX); return;} /* end of showrslt */