How to Find Remainder on C
The modulus operator "%" in C programming lets you divide two numbers and return the remainder. You do not retrieve any part of the whole number, so only the remaining value returns. For instance, the modulus operating returns "1" for the division problem five divided by two. The modulus operator is typically used in accounting and billing applications.
Instructions
-
-
1
Click the Windows "Start" button and select your C compiler in the list of programs. You can also open a C file by right-clicking the file, selecting "Open With," then clicking the C compiler program.
-
2
Scroll to the function you want to use to divide two variables. Type the following code to create two integer values and the modulus variable used to contain the results of the division:
int number1 = 5;
int number2 = 2;
int results = 0;
-
-
3
Type the following code to return the remainder of the division problem:
results = number1%number2;
The results variable now contains the number "1."
-
1