Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - C language judges whether a number is an integer.
C language judges whether a number is an integer.
Method 1:

# Contains &; stdio.h & ampgt;

# Contains &; math.h & ampgt;

Floating x;

...

if(fabs(x-(int)x)& amp; lt; 1e-8) printf ("X is an integer \ n ");

Elseprintf ("x is not an integer \ n ");

Method 2:

int c=(int)b,d=(int)(b+0.999999)

If (c==d)

Printf ("is an integer \ n");

other

Printf ("non-integer \ n");

Method 3:

Floating b;

...

if(b-(int)b==0)

Printf ("is an integer \ n");

other

Printf ("non-integer \ n");

Method 4:

Floating b;

...

If (b! =(int)b)

Printf ("non-integer \ n");

other

Printf ("is an integer \ n");