Programming Course in C# ¡Free!

Positive and negative

 Friday, April 05, 2013 published by Exercises C#
Proposed exercise

Write a C# program to get a number from the and answer whether it is positive or negative.

Output



Solution


using System;
public class PositiveAndNegative
{
public static void Main() 
{
int a;

Console.Write("Enter a number: ");
a=Convert.ToInt32(Console.ReadLine());

if(a>0)
Console.WriteLine("is positive"); 
if(a<0)
Console.WriteLine("is negative");
}
}