Check whether a number is positive or negative using if else in C Language

Introduction: In previous articles i explained How to swap two numbers without using temporary variable and Check whether a number is even or odd using if else statement and Else if ladder to perform operation on two numbers based on operator and Find greatest of two numbers using conditional operator and Find greatest of three numbers using multiple if statement and Find week days corresponding to number using switch case.
In this article i have written a program to check whether a number is positive or negative using if else statement in C Language. If the entered number is less than 0(zero) then it is Negative number else it is Positive number. Let's understand by a program in C language.

Implementation: Let's create a program to understand.

#include<conio.h>
#include<stdio.h>
main()
{
      int num;
      printf("Enter any number: ");
      scanf("%d",&num);
      if(num>0)
      printf("Number is positive");
      else
      printf("Number is negative");
      getch();
       }

  • Now run the program using  Ctrl + F9
Output:
First run:
Enter any number : -8
Number is negative
Second run
Enter any number : 20
Number is positive

Now over to you:

"If you like my work; you can appreciate by leaving your comments, hitting Facebook like button, following on Google+, Twitter, Linked in and Pinterest, stumbling my posts on stumble upon and subscribing for receiving free updates directly to your inbox . Stay tuned and stay connected for more technical updates."
Previous
Next Post »

If you have any question about any post, Feel free to ask.You can simply drop a comment below post or contact via Contact Us form. Your feedback and suggestions will be highly appreciated. Also try to leave comments from your account not from the anonymous account so that i can respond to you easily..