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

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

You May Also Like

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...