Q:

Write a C# Sharp program to check whether a given number is positive or negative

0

Write a C# Sharp program to check whether a given number is positive or negative

Sample Output:

Check whether a number is positive or negative:                                                               
----------------------------------------------
Input an integer : -10                                                                                        
-10 is a negative number.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;  
public class Exercise3  
{  
    public static void Main()  
    {
    int num;
    Console.Write("\n\n");
    Console.Write("Check whether a number is positive or negative:\n");
    Console.Write("----------------------------------------------");
    Console.Write("\n\n");
    Console.Write("Input an integer : ");
    num= Convert.ToInt32(Console.ReadLine());
    if (num >= 0)

 Console.WriteLine("{0} is a positive number.\n",num);
    else
        Console.WriteLine("{0} is a negative number. \n", num);
}
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now