ADVERTISEMENT
ADVERTISEMENT

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


ADVERTISEMENT


ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.