Skip to main content

Section 6.6 Remainders

A remainder is the amount that “remains” after division takes place. The mathematical operation that produces this remainder is called the modulo operation. Note that this is the fractional remainder, not a decimal value, so the result of the modulo operation should always be an integer. For example, the remainder when dividing 29 by 3 is 2 since 3 goes into 29 just 9 times and 29 - 9*3 = 2.
Suppose we want to know the remainder of the division of one integer by another. Can we do this with our current programming knowledge?

Compile and run the code below in your own C environment.

#include <stdio.h>

int main(void) {

    int num, denom, remainder;
    
    printf("Please enter a numerator and a denominator, separated by a space: ");
    scanf("%d %d", &num, &denom);
    
    remainder = /* please complete this line */
    
    printf("The remainder, when dividing %d by %d, is %d.\n", num, denom, remainder);
    
    return(0);
}