   Friday, 3 March 2017

Formula based program

Formula #6 (Area of triangle)

Enter length of base: 5
Enter height: 10
Area of triangle: 25

The program for the formula is written in C# programming language and will accept a number as length and height. Based on the formula it will find out the area of triangle.

Note: If you are new to C# and Console Application. Try to code First C# Program

Note: Read articles on how to use Loops and Conditions.

Let’s find out a simple and easy way to code these formula.

Practical Implementation:

using System;

namespace patternProblem.Formula
{
class Formula6     //area of triangle
{
static void Main(string[] args)
{
Console.Write("Enter length of base: ");
double baseLength = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter height: ");
double height = Convert.ToDouble(Console.ReadLine());
double area = 0.0;

area = ((baseLength * height) / 2);

Console.WriteLine("Area of triangle: {0}", area);

}
}
}

Output:
The input length here is 5 and height is 10. So, based on the area of triangle formula. The output is shown below:

Enter length of base: 5
Enter height: 10
Area of triangle: 25
Press any key to continue . . .

For any query, comment us below.

Skip to Main Table – Formula based program

Previous – Formula based program #5

Click imagination hunt to read latest blogs.

Keep learning and sharing... 