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!!!
Check number is Positive, Negative or Zero using C program
need an explanation for this answer? contact us directly to get an explanation for this answer