方法的重载

题目描述  

利用重载分别求圆、矩形和三角形的面积。(控制台应用程序)

海伦公式


公式描述:公式中,a,b,c分别为三角形三边长,P为半周长,S为三角形的面积。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 方法的重载
{
    class Program
    {
        //写在同一类中
        static void WriteArea(int radius)
        {
            double area = System.Math.PI * radius * radius;
            Console.WriteLine("您求的圆的面积是"+area);
        }
        static void WriteArea(int width, int length)
        {
            int area = width * length;
            Console.WriteLine("您求的矩形面积是" + area);
        }
        static void WriteArea(int a, int b, int c)
        {
            double p = (a + b + c) / 2;
            double area = System.Math.Sqrt(p * (p - a) * (p - b) * (p - c));
            Console.WriteLine("您求的三角形的面积是" + area);
        }
        static void Main(string[] args)
        {
            WriteArea(3, 4, 5);
            WriteArea(25);
            WriteArea(10, 20);
        }
    }
}

猜你喜欢

转载自blog.csdn.net/wyj____/article/details/80178427