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.
3. Exit.
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.
#include <stdio.h>
void main()
{
int number;
printf("Enter a number \n");
scanf("%d", &number);
if (number >= 0)
printf("%d is a positive number \n", number);
else
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”.
5. Exit.
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.
Here’s the list of Best Books in C Programming, Data-Structures and Algorithms
- Apply for Computer Science Internship
- Check C Books
- Practice Computer Science MCQs
- Practice BCA MCQs
- Check Computer Science Books