I want to divide 5 by 3 using C#. What operator can I use to get the remainder or modulus after dividing?
remainder = dividend % divisor; Finally, the quotient and remainder are displayed using printf( ) . printf("Quotient = %d\n", quotient); printf("Remainder = %d", remainder);
In the C Programming Language, the fmod function returns the remainder when x is divided by y.
Integer Division and the Remainder Operator C provides the remainder operator, %, which yields the remainder after integer division. The remainder operator is an integer operator that can be used only with integer operands. The expression x % y yields the remainder after x is divided by y.
Division in C In C language, when we divide two integers, we get an integer result, e.g., 5/2 evaluates to 2. As a general rule integer/integer = integer, float/integer = float and integer/float = float. So we convert denominator to float in our program, you may also write float in the numerator.
You can do this:
double answer = 5.0/3.0; int remainder = 5 % 3; int quotient = 5 / 3;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With