Practical applicationsĪrea of a rectangle calculations have a vast array of practical applications: construction, landscaping, internal decoration, architecture, engineering, physics, and so on and so forth. Since in multiplication the order in which the numbers are multiplied does not matter, you need not worry about switching the places of the two measurements. A rectangular bedroom with one wall being 15 feet long and the other being 12 feet long is simply 12 x 15 = 180 square feet. For example, a garden shaped as a rectangle with a length of 10 yards and width of 3 yards has an area of 10 x 3 = 30 square yards. Here, in this article, I try to explain how to calculate the Area of a Triangle in C# with Examples and I hope you enjoy this Area of Triangle Program article.The area of any rectangular place is or surface is its length multiplied by its width. In the next article, I am going to discuss the Area of Circle Program in C# with Examples. using System ĭouble Base = Convert.ToDouble(Console.ReadLine()) ĭouble Height = Convert.ToDouble(Console.ReadLine()) The following C# program allows the user to input the triangle base and height and then calculates the area and displays it in the console. The following is the formula to calculate the area of the Triangle. In some times instead of three sides of the triangle, you will get the base and height of the triangle and you will be asked to calculate the area of the triangle. using System Ĭonsole.Write("Enter the length of side 1:") ĭouble side1 = Convert.ToDouble(Console.ReadLine()) Ĭonsole.Write("Enter the length of side 2:") ĭouble side2 = Convert.ToDouble(Console.ReadLine()) Ĭonsole.Write("Enter the length of side 3:") ĭouble side3 = Convert.ToDouble(Console.ReadLine()) The following C# Program will allow the user to input the three sides of a triangle and then calculate the area and display it on the console. Example: Area of Triangle Program in C# using System Ĭonsole.WriteLine($"Value of side1 = ") ĭouble semiperimeter = (side1 + side2 + side3) / 2 ĭouble Area = Math.Sqrt(semiperimeter * (semiperimeter - side1) * (semiperimeter - side2) * (semiperimeter - side3)) Ĭonsole.Write("Area of a Triangle = " + Area) Įxample: Area of Triangle Program in C# by taking input from the user And the result will be store in the area variable.After calculating the semi perimeter, then we will calculate the area of the triangle by heron’s formula.Then semiperimeter will calculate by the formula of semi perimeter using the inputted value of side1, side2, and side3.First, we will take variables side1, side2, side3, semiperimeter, and area.To find the area of a triangle, we need to follow the below steps. Example: squareRoot = Math.Sqrt(number) Logic to Calculate the Area of Triangle in C# The built-in Sqrt function belongs to System.Math class. Sqrt: The Sqrt() function is used for the square root of a number.float: Floating-point numbers are used for decimal and exponential values.int: Integer variables are variables that must take an integer value (0, 1, 2, …).In this program, we are going to use the following Data type, and Function S is the semi perimeter of triangle and A is the area of triangle Example: Where, a, b and c are side of triangle with different length. Semi perimeter of Triangle (S) = (side1+side2+side3)/2 or S= (a+b+c)/2Īrea of a triangle (A) = √ The sum of the internal angles of a triangle is equal to 180 degrees. Or, in Geometry, a triangle is a three-sided polygon that consists of three edges and three vertices. A Triangle is 2D closed shape, it has three sides and three angles (corners). It is one of the basic shapes in geometry. Here, in this article, first, we will discuss what is triangle, then we will discuss how to calculate the area of a triangle and finally, we will see how to implement the area of triangle program in C#. Please read our previous article, where we discussed the Area of Square Program in C#. In this article, I am going to discuss how to calculate the Area of a Triangle in C# with Examples. How to Remove Duplicate Elements from an Array in C#īack to: C#.NET Programs and Algorithms Area of Triangle Program in C# with Examples.How to find the angle between hour and minute hands of a clock at any given time in C#.How to Perform Right Circular Rotation of an Array in C#.How to Perform Left Circular Rotation of an Array in C#.How to convert a one-dimensional array to a two-dimensional array in C#.How to convert a two-dimensional array to one-dimensional array in C#.How to Find All Substrings of a Given String in C#.How to Remove Duplicate Characters From a String in C#.Reverse Each Word in a Given String in C#.Data Structures and Algorithms Tutorials.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |