How to decide whether the result of an integer expression is an integer
c, c++, integer, math
Solution
You can use `%` to compute the remainder.
int denom = 2 * n;
int numer = 30 - n * (n - 1);
if (denom) {
if (numer % denom == 0) {
then good to go
}
} else {
/*...denominator is 0! */
}
Problem
I have an expression of `n` like `(30 - n(n - 1)) / 2n`. And I want search the possible n which will be my answer only when the result is an integer. Is there any way to decide whether the result of this expression is an integer or not. The only way that I can come up with is(in pseudo code ) : ``` for float n <- 1 to 100 do float result = expression(n); int part = (int) result; if ( result - part < EPS ) then good to go ```