Dremendo Tag Line

Check a number is positive or not in C

if else - Question 2

In this question, we will see how to check if a number is a positive number or not in C programming using the if else statement. To know more about if else statement click on the if else statement lesson.

Q2) Write a program in C to input a number and check if it is a positive number or not. A positive number is a number which is greater than 0.

Program

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

int main()
{
    int n;
    printf("Enter a number ");
    scanf("%d",&n);
    if(n>0)
    {
        printf("Positive Number");
    }
    else
    {
        printf("Not Positive Number");
    }
    return 0;
}

Output

Enter a number 5
Positive Number
video-poster