Progress

C Program Code to check a number Negative or Positive

C Program Code to check a number Negative or Positive

C language is one of the best programming languages to start programming journey. The main reason behind this is that you will get a close understanding of how languages work behind the scenes. If you want to learn C language then better start by reading and understanding some basic examples before diving deep in concepts. Here is a C program code to check a number is negative or positive.

Copy
#include <stdio.h>

int main(){
    float num;
    printf("Enter the number\n");
    scanf("%2f", &num);
    if(num>0.0){
        printf("It is Positive\n");
    }else if(num==0.00){
        printf("0 is neither Positive nor negative.\n");
    }else{
        printf("It is Negative\n");
    }
}
Output
Enter the number
-32
It is Negative

Simple and easy logic, if the number is less then zero then it is negative greater than zero means positive.

But there are few more things going here and you must have noticed that we are using float data type. We are taking input in 2 digits decimal form and storing it in variable num. Now the checking conditions are normal as defined.

However, there are multiple ways to solve any problem. This was one C program code to check a number is positive or negative. If you have any alternative ideas submit in comments and I will add them here.

If you are going to start learning C language then you may need to check out the best operating system for C programming language.

Check this link for learning C Language.

If you have any doubt feel free to ask in comments.

Share the Post ;)

Related Posts