How to use fmod inside a if function?

Code:`double List ()`

{

double Div = N;

while (--Div > 0){

if((N % Div) == 0 )

printf("%.lf +", Div);

}

}

Printable View

- 08-01-2002yusiyefmod problem
How to use fmod inside a if function?

Code:`double List ()`

{

double Div = N;

while (--Div > 0){

if((N % Div) == 0 )

printf("%.lf +", Div);

}

}

- 08-01-2002yusiyeRe: fmod problemQuote:

*Originally posted by yusiye*

**How to use fmod inside a if function?**

Code:`double List ()`

{

double Div = N;

while (--Div > 0){

if((N % Div) == 0 )

printf("%.lf +", Div);

}

}

Code:`double List ()`

{

double Div = N;

d = fmod(Div, N);

while (--Div > 0){

if( d == 0 )

printf("%.lf +", Div);

}

}

- 08-01-2002gabulldog
fmod returns the remainder of a divisor and dividend presented by the code. It is a very useful tool, but you need to remember that floats and doubles are not always exact, so you might not get the desired result.

The code you have presentedCode:`double List ()`

{

double Div = N;

while (--Div > 0){

if((N % Div) == 0 )

printf("%.lf +", Div);

}

}

Code:`if((fmod(N,Div))==0)`

Code:`if(((int)N % (int)Div)) == 0)`

What's it supposed to do? - 08-01-2002Prelude
When comparing floating-point values to an exact value such as zero, you need to remember that floating-point is an approximation and it's best to test for "close enough" instead of exactly the same.

C provides the FLT_EPSILON, DBL_EPSILON, and LDBL_EPSILON macros in float.h for such use.

-Prelude