×

C Programs

C Basic & Conditional Programs

C Looping Programs

C String Programs

C Miscellaneous Programs

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.

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;
}

Output

    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!!!

C Looping Programs »

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.