C program to check whether an integer is positive or negative

C program to check whether an integer is positive or negative

Q:-Write a program to check whether an integer is positive or negative

In this c programming example, you will learn to check whether a number is negative or positive.


#include<stdio.h>
#include<conio.h>

void main() 
{
int num; 
clrscr();
    printf("\n Enter a number::");
    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");
getch();
 }

Output

  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. o. 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.
TOP