Tuesday, March 31, 2020

C Program check number is positive or negative using if else

C Program check number is positive or negative using if else 

#include 
int main()
{
    double num; // constant number
    printf("Enter a number: "); // enter user 
    scanf("%lf", &num); // storing constant value
    if (num <= 0.0) // check number is greater or not
 {
        if (num == 0.0)
            printf("You entered 0.");
        else
            printf("You entered a negative number.");
    } else
        printf("You entered a positive number.");
    return 0;
}

Output

Enter a number : 32
You entered Positive number

Happy Coding

0 comments:

Post a Comment

Recent Posts