C Program to Check if a Number is Positive, Negative or Zero
source link: https://www.geeksforgeeks.org/videos/c-program-to-check-if-a-number-is-positive-negative-or-zero/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
C Program to Check if a Number is Positive, Negative or Zero
- 70 Views
- 21/08/2022
In this video, we will write a C program to Check if an input number is Positive Negative or Zero.
Basically, a number that is greater than zero is known as a Positive number and denoted by a plus (+) sign. Whereas numbers that are less than zero are known as Negative numbers and denoted by a minus(-)sign.
Algorithm:
Step 1: Take input of a number from the user.
Step 2: Check that number:
Step 2.1: If the number is less than zero, then print the number as Negative.
Step 2.2: If the number is greater than zero then print that the number is Positive.
Step 2.3: If the input number is equal to zero then print 0.
Step 3: Stop the program.
In the video to check whether the number is positive/negative/zero we use two different methods:
1. Using the if-else ladder condition
2. Using Nested of if-else
Examples:
Input: n = -37
Output: Negative
Input: n = 160
Output: Positive
Input: n = 0
Output: Zero
Apart from that, we will see the time and space complexity of both the methods,i.e
Time Complexity: O(1)
Space Complexity:(1)
C program to Check Whether a Number is Positive or Negative or Zero
https://www.geeksforgeeks.org/c-program-to-check-whether-a-number-is-positive-or-negative-or-zero/
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK