
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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 Articles
- Program to check if a number is Positive, Negative, Odd, Even, Zero?
- Java Menu Driven Program to Check Positive Negative or Odd Even Number
- C program to Check Whether a Number is Positive or Negative or Zero?
- How to check if a number is positive, negative or zero using Python?
- Check if a number is positive, negative or zero using bit operators in C++
- C++ Program to Check Whether a Number is Positive or Negative
- Python Program to Check if a Number is Positive, Negative or 0
- C++ Program to Check Whether Number is Even or Odd
- What is zero if it is not a negative or positive number?
- Java Program to Check Whether a Number is Positive or Negative
- Haskell Program to Check Whether a Number is Positive or Negative
- Java Program to Check Whether a Number is Even or Odd
- Haskell Program to Check Whether a Number is Even or Odd
- C Program to Check if count of divisors is even or odd?
- How to Check if a Number is Odd or Even using Python?

Advertisements