Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - My little brother just learned C language and met a problem. . Write a program: ask for a positive integer. If it is not a positive integer, an error will be reported.
My little brother just learned C language and met a problem. . Write a program: ask for a positive integer. If it is not a positive integer, an error will be reported.
It's simple. You can assign an input number to a variable. For example:

The input is 3.2 and an int variable is defined. Details are as follows:

Suppose n=3.2// Suppose n is the number you define to store keyboard input.

int a;

Floating b;

a = n; //At this time, a is equal to the integer part of n, which is 3;

b = n-a; //b is used to store the fractional part of n, and b is equal to 3.2-3;

If(b==0)printf ("input integer");

Else printf ("input floating-point number");

This should be clear. If you don't understand, hey, I ... ...