

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# Program to check if a number is Positive, Negative, Odd, Even, Zero
Check for the following conditions −
For odd and even, check for the remainder when the number is divided by 2 −
// checking for odd/ even if(n % 2 == 0) { Console.WriteLine("Even"); } else { Console.WriteLine("Odd"); }
For positive, negative and checking whether a number is 0 or not −
if (n < 0) { Console.WriteLine("Negative Number!"); } else if(n == 0) { Console.WriteLine("Zero"); } else { Console.WriteLine("Positive Number!"); }
The following is the complete code:
Example
using System; using System.Collections.Generic; public class Demo { public static void Main(string[] args) { int n = 19; // checking for odd/ even if (n % 2 == 0) { Console.WriteLine("Even"); } else { Console.WriteLine("Odd"); } // checking for positive, negative or 0 if (n < 0) { Console.WriteLine("Negative Number!"); } else if (n == 0) { Console.WriteLine("Zero"); } else { Console.WriteLine("Positive Number!"); } } }
Output
Odd Positive Number!
- Related Questions & Answers
- Program to check if a number is Positive, Negative, Odd, Even, Zero?
- How to check if a number is positive, negative or zero using Python?
- C program to Check Whether a Number is Positive or Negative or Zero?
- Check if a number is positive, negative or zero using bit operators in C++
- Python Program to Check if a Number is Positive, Negative or 0
- Java Program to Check Whether a Number is Positive or Negative
- How to Check if a Number is Odd or Even using Python?
- Java Program to Check Whether a Number is Even or Odd
- C++ Program to Check Whether Number is Even or Odd
- PHP program to check if the total number of divisors of a number is even or odd
- Java program to find if the given number is positive or negative
- C Program to Check if count of divisors is even or odd?
- Java Program to check if count of divisors is even or odd
- 8085 program to check whether the given number is even or odd
- Check whether product of integers from a to b is positive, negative or zero in Python
Advertisements