BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

C Program to check whether a given integer is positive or negative

Last Updated: May 22, 2024 by Chaitanya Singh | Filed Under: C Programs

In this article, we will write a C Program to check whether a given integer is positive or negative. For example, if user enters -5 then program should print that it’s a negative number.

C Program to check if an integer is positive or negative

In the following program, we are using if-else statement. If the input number is greater than zero then its a positive number else it is a negative number. If the number is zero then it is neither positive nor negative.

#include <stdio.h>

void main()
{
int num;

// Prompt user to enter an integer number
printf("Enter an integer number: \n");
scanf("%d", &num);

// Check if the number is positive, negative, or zero
if (num > 0)
printf("%d is a positive number \n", num);
else if (num < 0)
printf("%d is a negative number \n", num);
else
printf("0 is neither positive nor negative");

return 0;
}

Output:

Output 1:

Enter an integer number:
0
0 is neither positive nor negative

Output 2:

Enter an integer number:
-3
-3 is a negative number

Output 3:

Enter an integer number:
100
100 is a positive number

Related C Programs:

  • C Program to check whether a number is prime or not
  • C Program to check if a number is divisible by 3 and 5
  • C Program to generate multiplication table
  • C Program to validate a given date
  • Java Program to check if a number is positive or negative

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

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

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap