Search This Blog


Wednesday, 17 April 2019

C Program to Check if a given Integer is Positive or Negative

WELCOME BACK CODERS . SO HERE IS OUR NEW BLOG ON TO FIND THAT THE GIVEN INTEGER IS POSITIVE OR NEGATIVE.  MAKE SURE TO CHECK OUT OUR OTHER BLOGS TOO.

IN THIS BLOG WE WILL FIND THAT THE GIVEN INTEGER IS POSITIVE OR NEGATIVE WHICH IS VERY EASY TO CODE .. THE USER NEEDS TO ENTER THE INTEGER AND THEN THIS CODE WILL SHOW IF ITS POSITIVE OR NEGATIVE.


Program Explanation
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.

CODE

#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);
}




OUTPUT






No comments:

Post a Comment