In this tutorial you will learn about the C Program for Positive or Negative Number and its application with practical example.
C Program for Positive or Negative Number
In this tutorial, we will learn to create a C program that will check the number is Positive or Negative Numbers in C programming.
Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- Conditional Statements in c programming.
1. Declare the variables for the program.
2. Taking the input numbers.
3. Passing that number to the conditions for the checking.
4. Checking the input number.
5. Print the number is positive or negative.
6. End the program.
Program for Positive or Negative Number.
In this program, we will first take the input number from the user to check. After taking the input, we will use that number in conditional statements to check. Then we will print the output of the program using the “printf() ” function. Whether it’s a positive, negative, or zero value.
INPUT NUMBER BE 123456.
THEN THE PROGRAM WILL RETURN THE OUTPUT AS A POSITIVE NUMBER.
IF A INPUT NUMBER IS -142.
THEN THE PROGRAM WILL RETURN THE OUTPUT AS A NEGATIVE NUMBER.</strong>
With the help of this program, we can check Positive or Negative Numbers.
//Declaring the required variable for the program
//n = it will hold an integer value for the input number.
//Taking the input number from the user for the program.
printf("Enter any number:\n");
//Scanning the input number from the user.
//Checking the positive and negative number from the user.
if (n >= 0)
if (n > 0)
//Printing the number is positive
printf("%d is Positive", n);
//Printing the number is zero not positive not negative.
printf("You have entered Value zero.");
//Printing the number is negative
printf("%d is Negative", n);
In the above program, we have first initialized the required variable.
- n = it will hold the integer input value of the number.
Taking the input number from the user in the integer format.
In this section of code for the program to check, a number is a positive number or a negative number, or a Zero.
Printing the output for the program after checking the conditions.