C# program to take a number as input and tells its positive or negative

Views: 119   

Following program shows you how to take a number as input and tells its positive or negative.
In this program we get number from user, and if the number is less than zero it prints negative, and if the number is grater than zero it prints positive

using System;

class MainClass {
  public static void Main (string[] args) {
     Console.WriteLine("Please enter a number:");
    int input = Convert.ToInt32(Console.ReadLine());
    if (input < 0) {
      Console.WriteLine("Given number is -ve");
      } else {
        Console.WriteLine("Given number is +ve");
      }
  }
}

Output:

Example1:

Please enter a number:
 12
Given number is +ve

Example2:

Please enter a number:
 -5
Given number is -ve
On By