C# Program to Check Whether a Number is Positive or Not

C# is a versatile programming language widely used in various applications. In this example, we will explore a straightforward C# program to determine whether a given number is positive, demonstrating the language’s ability to perform basic conditional checks.

Problem Statement

Write a C# program to check whether a given number is positive or not. The program should take an input number and determine if it is greater than zero. If it is, the number is considered positive; otherwise, it is not.

C# Program to Check Whether a Number is Positive or Not

using System;

class Program
{
    static void Main()
    {
        Console.Write("Enter a number: ");
        double number = Convert.ToDouble(Console.ReadLine());

        if (IsPositive(number))
        {
            Console.WriteLine(number + " is a positive number.");
        }
        else
        {
            Console.WriteLine(number + " is not a positive number.");
        }
    }

    static bool IsPositive(double num)
    {
        return num > 0;
    }
}

Input / Output

C# Program to Check Whether a Number is Positive or Not

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...