/* * read_divide_ints.c -- * * Write a function that reads integer numbers character-by-character * and that returns the corresponding int value (read until end-of-line * and ignore all characters that are not digits). Use this function to * read two int values, then print the quotient and remainder that result * from dividing the first value by the second value. Also print the * result of dividing the two numbers using the rules of floating-point * division. */ #include // Function prototype int read_int(); int main() { int dividend=0, divisor=0, quotient=0, remainder=0; float flt_div = 0.0; printf("Enter the dividend: "); // Read the dividend by invoking the read_int() function dividend = read_int(); printf("Enter the divisor: "); // Read the divisor by invoking the read_int() function divisor = read_int(); // Perform the arithmetic operations quotient = dividend / divisor; remainder = dividend % divisor; flt_div = 1.0 * dividend / divisor; // Print the results printf("dividend = %d; divisor = %d\n", dividend, divisor); printf("The quotient is %d\n", quotient); printf("The remainder is %d\n", remainder); printf("The result of floating-point division is %.2f", flt_div); return 0; } // Function implementation int read_int() { int num = 0; int c; // Read integer number character-by-character while ((c = getchar()) != '\n') { if (c >= '0' && c <= '9') { num = 10*num + c - '0'; } } return num; }