This is a C program to check whether a given integer is positive or negative.
The program takes the given integer and checks whether the integer is positive or negative.
1. Take the integer which you want to check as input.
2. Check if it is greater or lesser than zero and print the output accordingly.
Here is source code of the C program which checks a given integer is positive or negative. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
printf("Enter a number \n");
if (number >= 0)
printf("%d is a positive number \n", number);
printf("%d is a negative number \n", number);
1. Take the integer which you want to check as input and store it in a variable number.
2. Using if,else statements check whether the integer is greater or lesser than zero.
3. If it is greater than or equal to zero, then print the ouput as “it is a positive number”.
4. If it is lesser than zero, then print the ouput as “it is a negative number”.
Case:1 Enter a number -10 -10 is a negative number Case:2 Enter a number 45 45 is a positive number
Sanfoundry Global Education & Learning Series – 1000 C Programs.