Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get remainder and mod by dividing using C# [closed]

Tags:

I want to divide 5 by 3 using C#. What operator can I use to get the remainder or modulus after dividing?

like image 441
user1578422 Avatar asked Feb 13 '13 07:02

user1578422


People also ask

How do you divide a remainder in C?

remainder = dividend % divisor; Finally, the quotient and remainder are displayed using printf( ) . printf("Quotient = %d\n", quotient); printf("Remainder = %d", remainder);

Is there a remainder function in C?

In the C Programming Language, the fmod function returns the remainder when x is divided by y.

What does remainder mean in C?

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.

Can you divide in C?

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.


1 Answers

You can do this:

 double answer = 5.0/3.0;   int remainder = 5 % 3;   int quotient = 5 / 3; 
like image 183
T.Z Avatar answered Oct 01 '22 19:10

T.Z