How to check if the number is positive or negative in C# ?


Grammarly

More than 40 Lakhs Students and Professionals use Grammarly for their spell and grammar checks. You can register and try for free.

You can use the > and < operator to check if the number is a positive or negative number in C#.

How to check if the number is positive or negative in C# ?

If the number is less than zero , it can be considered as negative number. If the number is greater than zero , it is a positive number. Below is a sample code that finds out if the number is a positive or negative number.

using System;
namespace ACCode
{
    class Program
    {
        static void Main(string[] args)
        {
            int input1 = 85;
            bool positiveNumber = input1 > 0;
            bool negativeNumber = input1 < 0;
            Console.WriteLine(positiveNumber);
            Console.WriteLine(negativeNumber);
            Console.ReadLine();
        }
      
    } 
}

Grammarly

More than 40 Lakhs Students and Professionals use Grammarly for their spell and grammar checks. You can register and try for free.
%d bloggers like this: