In this C program, we will learn how to write a program to check whether the input integer number is positive or negative. In this program, we are displaying the message using printf
function and read the input taken from the user using scanf
function.
Here is the code of the program to check whether the input integer number is positive or negative.
/* Description: C program to check whether the input
* integer number is positive or negative.
*/
#include <stdio.h>
void main()
{
int num;
printf("Enter a number: \n");
scanf("%d", &num);
if (num > 0){
printf("%d is a positive number \n", num);
}
else if (num < 0){
printf("%d is a negative number \n", num);}
else{
printf("0 is neither positive nor negative");
}
}
Enter a number:
5
5 is a positive number
--------------------------------
Process exited after 3.742 seconds with return value 24
Press any key to continue . . .
Comments