Area of Square in C#

Area of Square Program in C# with Examples

In this article, I am going to discuss how to calculate the Area of a Square in C# with Examples. Please read our previous article, where we discussed the Area of Rectangle Program in C#. Here, in this article, first, we will discuss what is Square, then we will discuss how to calculate the area of a square and finally, we will see how to implement the area of the square program in C#.

What is a Square?

According to Wikipedia, in geometry, a square is a regular quadrilateral, which means that it has four equal sides and four equal angles (90-degree angles, or 100-gradian angles or right angles). It can also be defined as a rectangle in which two adjacent sides have equal lengths. A square is a closed, two-dimensional shape with 4 equal sides and four right angles.Ā Ā 

How to Calculate the Area of a Square?

Area of square = side * sideĀ OrĀ Ā 
A=S * S, where, A is the area of the square and S is the side of the squareĀ 

For example: Let say S i.e. side = 5, then the area of the square is 25 i.e. 5 * 5Ā Ā Ā Ā 
Explanation: area of the square is the multiply of side with sideĀ Ā 

How to Calculate the Area of a Square? Ā 

In this program, we can use the following Datatype

  1. int: IntegerĀ variables are variables that must take an integer value (0, 1, 2, …).Ā Example:Ā variables int num1 = 5Ā 
  2. float: Floating-point numbers are used for decimal and exponentialĀ values. ItĀ is a primitive data type.Ā Example:Ā variables float num1 = 5.5Ā 
Logic to Calculate the Area of Square in C#Ā Ā Ā 

For finding the area of the square we will multiply simply side with itself. The following are the steps that we need to follow to solve this problem.Ā Ā Ā 

  1. First, we will define side S.Ā Ā 
  2. Then define the area of square A.Ā Ā Ā 
  3. Then calculate the area of the square by multiplying side(S) with side(S).Ā Ā 
  4. After multiplying, the result will assign in A and show the output.Ā Ā 
Example: Area of Square Program in C#.

The following C# Program will calculate the area of the square.

using System;
public class AreaOfSquare
{
    public static void Main()
    {
        int Side = 10;
        int Area = Side * Side;
        Console.WriteLine($"Area of Square with side {Side} is {Area}");
        Console.ReadKey();
    }
} 

Output: Area of Square with side 10 is 100Ā Ā 

Example: Area of Square Program in C# by taking input from the user

The following C# Program will allow the user to input the side of the square and then calculate the area and display it on the console.

using System;
public class AreaOfSquare
{
    public static void Main()
    {
        Console.WriteLine("Enter the Side of Square: ");
        int Side = Convert.ToInt32(Console.ReadLine());
        int Area = Side * Side;
        Console.WriteLine($"Area of Square with side {Side} is {Area}");
        Console.ReadKey();
    }
}
OutputĀ 

how to calculate the Area of a Square in C# with Examples

Time Complexity: O(1)Ā 

In the next article, I am going to discuss the Area of the Triangle Program in C# with Examples. Here, in this article, I try to explain how to calculate the Area of a Square in C# with Examples and I hope you enjoy this Area of Square Program article.

Leave a Reply

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