Is there any function in .Net to find out how many times a number is contained in another number with 0 remainders for example:
- 10 and 2 = 5 times
- 7 and 2 = 3 times
- 3 and 2 = 1 time
Is there any function in .Net to find out how many times a number is contained in another number with 0 remainders for example:
There are several options doing so:
Integer division + https://msdn.microsoft.com/en-us/library/aa691373(v=vs.71).aspx:
int integerX = integerY / integerZ;
By casting a floating-point result:
int integerX = (int) floatY / floatZ;
Integer division is probably what you need. it always result as same as Floor in math.
How ever there are some methods in Math class that may be useful. like DivRem. there is also overload that accepts long
type.
int remainder;
int quotient = Math.DivRem(7, 2, out remainder);
int whatYouWant = quotient;
You mean Remainders. Solution:
int a = 9;
int b = 4;
int result = (a - a % b) / b;
The % means modulus so this formula first removes what would be the remainder and then performs the division. Similarly you can find the remainder without doing the division using:
int result = a % b;