C Program to Check Whether a Number is Positive or Negative

C Program to Check Whether a Number is Positive or Negative

C program to check whether a given number is positive or negative or zero; Through this tutorial, we will learn how to check whether given number a is positive, negative, or zero in c program.

C Program to Check Whether a Number is Positive or Negative

  • Algorithm to Check Whether a Number is Positive or Negative
  • C Program to Check Whether a Number is Positive or Negative using If Statement
  • C Program to Check Whether a Number is Positive or Negative Using Nested if…else

Algorithm to Check Whether a Number is Positive or Negative

Use the following algorithm to write a c program to check whether a given number is positive or negative or zero; as follows:

  • Start program
  • Read the a number in program and store it into variable.
  • Check the number is positive, negative or zero using if or nested if else statement.
  • Print a number positivem negative or zero.
  • Stop program.

C Program to Check Whether a Number is Positive or Negative using If Statement

/**
 * C program to check positive negative or zero using if else
 */

#include <stdio.h>

int main()
{
    int num;
    
    /* Input number from user */
    printf("Enter a number: ");
    scanf("%d", &num);
    

    if(num > 0)
    {
        printf("Number is POSITIVE");
    }
    else if(num < 0)
    {
        printf("Number is NEGATIVE");
    }
    else
    {
        printf("Number is ZERO");
    }

    return 0;
}

The output of the above c program; as follows:

Enter a number: 10
Number is POSITIVE

C Program to Check Whether a Number is Positive or Negative Using Nested if…else

#include <stdio.h>
int main() {
    double num;
    printf("Enter a number: ");
    scanf("%lf", &num);
    if (num <= 0.0) {
        if (num == 0.0)
            printf("Number is ZERO");
        else
            printf("Number is NEGATIVE");
    } 
    else
        printf("Number is POSITIVE");
    return 0;
}

The output of the above c program; as follows:

Enter a number: 12.3
Number is POSITIVE

Recommended C Programs

AuthorAdmin

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *