Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to judge integers and decimals in C language? For example, if I input floating-point data, what can I do to remind it that there is a problem?
How to judge integers and decimals in C language? For example, if I input floating-point data, what can I do to remind it that there is a problem?
See if this method meets your requirements.

12.000 is an integer, but it is followed by several zeros.

# include & ltstdio.h & gt

void main()

{

Floating-point number;

int NB

Printf ("enter a number");

scanf("%f ",& ampnum);

NB =(int)num;

while( 1)

{

if((num-NB)! =0)

{

Printf ("\ nYou entered a decimal, please re-enter:");

scanf("%f ",& ampnum);

NB =(int)num;

}

other

{

Break;

}

}

printf("\nnum=%f ",num);

}