
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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!
Advertisements