Q:

C program to check whether number is POSITIVE, NEGATIVE or ZERO until user doesn\'t want to exit.

0

C program to check whether number is POSITIVE, NEGATIVE or ZERO until user doesn't want to exit.

This program will read an integer number and check whether entered number is Positive, Negative or Zero until user does not want to exit.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Check number is Positive, Negative or Zero using C program

/*  C program to check whether number is 
    POSITIVE, NEGATIVE or ZERO until user doesn’t want to exit.*/

#include <stdio.h>

int main()
{
    int num;
    char choice;
    do {
        printf("Enter an integer number :");
        scanf("%d", &num);

        if (num == 0)
            printf("Number is ZERO.");
        else if (num > 0)
            printf("Number is POSITIVE.");
        else
            printf("Number is NEGATIVE.");

        printf("\n\nWant to check again (press Y/y for 'yes') :");
        fflush(stdin); /*to clear input buffer*/
        scanf(" %c", &choice); /*Here is a space before %c*/
    } while (choice == 'Y' || choice == 'y');

    printf("\nBye Bye!!!");

    return 0;
}
    Enter an integer number :0
    Number is ZERO.

    Want to check again (press Y/y for 'yes') :Y
    Enter an integer number :1234
    Number is POSITIVE.

    Want to check again (press Y/y for 'yes') :Y
    Enter an integer number :-345
    Number is NEGATIVE.

    Want to check again (press Y/y for 'yes') :y
    Enter an integer number :45
    Number is POSITIVE.

    Want to check again (press Y/y for 'yes') :N

    Bye Bye!!!

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C program to find factorial of a number... >>
<< C program to print table of numbers from 1 to 20...