Home > Backend Development > C++ > body text

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

王林
Release: 2023-08-25 19:17:05
forward
1021 people have browsed it

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

A number which is greater than 0 is positive and less than 0 are negative. The concept of positive and negative is very important in number theory and programming also. Calculations rely on this concept only.

Input: 0
Output:0 is zero
Copy after login

Explanation

Using conditional statement check the number with 0 weather it is greater than 0 or smaller than 0.

Example

#include <iostream>
using namespace std;
int main() {
   int n=0;
   if(n>0) {
      printf("%d is positive",n);
   } else if(n<0) {
      printf("%d is negative",n);
   } else {
      printf("%d is zero",n);
   }
   return 0;
}
Copy after login

The above is the detailed content of C program to check if a number is positive, negative or zero?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template