Computer for SEE and NEB

It is a complete SEE and NEB solution for computer science. It includes Computer Fundamentals, Database (SQL), Programming in C QBASIC, CSS, JavaScript, and PHP for beginners.

Breaking

Post Top Ad

Your Ad Spot

Saturday, July 16, 2022

C program to check whether a number is positive, negative or zero

C program to check whether a number is positive, negative, or zero

 

C program to check whether a number is positive, negative, or zero


Introduction:

In programming, it is often necessary C program to check whether a number is positive, negative, or zero. This information can be used to perform further computations or make decisions in the program. In this article, we will focus on a C program to check whether a number is positive, negative, or zero.

Before we dive into the code, let's briefly discuss the concepts of positive, negative, and zero numbers. A positive number is greater than zero, a negative number is less than zero, and zero is neither positive nor negative.

Now, let's take a look at the C program that can determine whether a given number is positive, negative, or zero:

Coding of the program:



Explanation of the program:


The program first prompts the user to enter a number using the printf() and scanf() functions. The input is stored in the variable num. We then use a series of if and else if statements to check the sign of num. If num is greater than 0, the program prints a message saying that it is a positive number. If num is less than 0, the program prints a message saying that it is a negative number. If num is equal to 0, the program prints a message saying that it is zero.

Output:




Conclusion:


In conclusion, learning how to write a C program to check whether a number is positive, negative, or zero is essential for any developer. It is a basic programming task that can be performed with ease once you know how to do it. This article has provided a step-by-step guide to creating a simple program that will help you determine the sign of any given number.

Remember, programming is all about practice, and the more you practice, the better you become. So, go ahead and start practicing writing C programs to check whether a number is positive, negative, or zero.



FAQs


Q. What is a positive number? 
Ans: A positive number is a number greater than zero.

Q. What is a negative number? 
Ans: A negative number is a number less than zero.

Q. What is a zero number?  
Ans: zero number is a number that equals zero.




No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages