Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C Language Examples - Checking Positive/Negative/Zero

C Language Examples - Checking Positive/Negative

C Language Examples C Language Examples

The user enters a number, and the program determines whether it is positive, negative, or zero.

Example

#include

<

stdio.h

int

main

(

)

{

double

number

;

printf

(

"

Enter a number:

"

)

;

scanf

(

"

%lf

"

, &

number

)

;

if

(

number

<=

0

.0

)

{

if

(

number

==

0

.0

)

printf

(

"

What you entered is 0.

"

)

;

else

printf

(

"

What you entered is a negative number.

"

)

;

}

else

printf

(

"

What you entered is a positive number.

"

)

;

return

0

;

}

Running result:



输入一个数字: 9

你输入的是正数。

C Language Examples C Language Examples