Please login

Prime

Prepinsta Prime

Video courses for company/skill based Preparation

(Check all courses)
Get Prime Video
Prime

Prepinsta Prime

Purchase mock tests for company/skill building

(Check all mocks)
Get Prime mock

C Program to check if a Number Is Positive Or Negative

A number is positive or negative in C programming

Write a C program to find  Number is a positive or Negative

The following concept will test weather a number is positive or negative. It is done by checking where the number lies on the number line. The following algorithm will help to check this condition.

  • If the input number is greater than zero then it is a positive number.
  • If the input number is less than zero it is a negative number.
  • If the number is zero then it is neither positive nor negative.

Same logic we have followed in the below C program.

 

Working

  • Step 1. Start
  • Step 2. Enter the number.
  • Step 3. If the number is less than or equal to zero, check if it is zero.
  • Step 4. If the number is zero, print, “, The number is zero.”
  • Step 5. If the number is less than zero, print, “The number is negative.”
  • Step 6. If the number is more than zero, print, “The number is positive.”
  • Step 7. Stop

C Code

     
    #include<stdio.h>
     int main()
     {
     int num;
     printf(“Insert a number: “);
     scanf(“%d”, &num);
     //Condition to check if the number is negative or positive
     if (num <= 0)
     {
     if (num == 0)
        printf(“The number is 0.”);
     else
        printf(“The number is negative”);
     }
     else
        printf(“The number is positive”);
     return 0;
     }



Output

Insert a number: 56
The number is positive

                                                                                        

2 comments on “C Program to check if a Number Is Positive Or Negative”