C#计算三角形面积
程序员文章站
2022-04-01 16:08:42
...
c#计算三角形面积
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _3_2
{
class Program
{
class Triangle
{
public int a, b, c;
public double getArea(int a,int b,int c)
{
float p = (a + b + c) / 2;
double s = Math.Sqrt(p * (p - a) * (p - b) * (p - c));
return s;
}
}
static void Main(string[] args)
{
Triangle tr = new Triangle();
Console.WriteLine("三角形的面积为:{0}", tr.getArea(3, 4, 5));
Console.ReadKey();
}
}
}