Basic Programming C# Examples

C# Program to Check If Given number is Positive or Negative

The Program in C# Program to Check If Given number is Positive or Negative is given below:

using System;

namespace PositiveNegativeCheck
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello Codeauri Family,enter a number here to know whether the numbe is positive or negarive: ");
            int num = Convert.ToInt32(Console.ReadLine());
            if (num > 0)
            {
                Console.WriteLine("Okay,the number is positive.");
            }
            else if (num < 0)
            {
                Console.WriteLine("Okay,the number is negative.");
            }
            else
            {
                Console.WriteLine("The number is zero.");
            }
            Console.ReadLine();
        }
    }
}

Output:

Hello Codeauri Family,enter a number here to know whether the numbe is positive or negarive:
10
Okay,the number is positive.

Pro-Tips💡

Here are the step by step execution of above program:

  1. using System;: This line includes the System namespace, which contains various classes and methods used in the program.
  2. namespace PositiveNegativeCheck: A namespace is used to organize and group classes in a logical manner.
  3. class Program: A class is a blueprint that defines the properties and methods of an object.
  4. static void Main(string[] args): The Main method is the entry point of the program and is executed first when the program runs.
  5. Console.WriteLine("Hello Codeauri Family,enter a number here to know whether the numbe is positive or negarive: ");: This line displays a message on the console asking the user to enter a number.
  6. int num = Convert.ToInt32(Console.ReadLine());: This line reads a string from the console and converts it to an integer.
  7. if (num > 0): This checks if the number is greater than 0. If the condition is true, the code inside the if block is executed.
  8. else if (num < 0): This checks if the number is less than 0. If the previous if condition was false, and this condition is true, the code inside the else if block is executed.
  9. else: If both the previous conditions are false, the code inside the else block is executed.
  10. Console.ReadLine();: This line is used to keep the console open so that the output can be read.

Learn C-Sharp ↗

C-sharp covers every topic to learn about C-Sharp thoroughly.

Learn C Programming ↗

C-Programming covers every topic to learn about C-Sharp thoroughly.

Learn C++ Programming↗

C++ covers every topic to learn about C-Sharp thoroughly.

Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

Related Posts

Programming Languages( Types, Pros and Cons)-Codeauri

What are the types or levels of Programming Languages? The types or levels of programming languages are divided into two types: Types Of Programming Languages: 1.Machine-level Language :1st…

C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

Leave a Reply

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

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X