求三角形性质

来源:互联网 发布:ui设计师美工的区别 编辑:程序博客网 时间:2024/04/30 08:36
// Copyright (c) 2014软件技术2班      // All rights reserved.       // 作    者:B23        // 完成日期:2014年 10 月 31 日       // 版 本 号:v1.0            //输入描述:输入三角形的三边 a, b, c,值,根据其数值,判断是否能构成三角形,若能,还有判断其三角形的性质:等边三角形,等腰三角形,直角三角形和任意三角形。using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace triangle{    class Program    {        static void Main(string[] args)        {            double a, b, c;  //定义 a ,b , c , 变量            Console.Title = ("判断三角形形状");  //定义标题名            Console.WriteLine("请依次输入三角形三边的长度:");            Console.WriteLine("输入a边的长:");            a = Convert.ToDouble(Console.ReadLine());  //从键盘输入一个数,并赋予给变量a            Console.WriteLine("输入b边的长:");            b = Convert.ToDouble(Console.ReadLine());  //从键盘输入一个数,并赋予给变量b            Console.WriteLine("输入c边的长:");            c = Convert.ToDouble(Console.ReadLine());  //从键盘输入一个数,并赋予给变量c            if (a + b <= c || a + c <= b || b + c <= a)   //if 语句 判断三角形成立是否成立                          {                Console.WriteLine("不是三角形");            }            else            {                if (a == b && a == c && b == c)     //判断等边三角形                {                    Console.WriteLine("这个是等边三角形");                }                else if (a == b || b == c || c == a)  //判断等腰                {                    Console.WriteLine("这个是等腰三角形");                }                else if (a * a == b * b + c * c || b * b == a * a + c * c || c * c == a * a + b * b)  //判断直角                {                    Console.WriteLine("这个是直角三角形");                }                else    //判断以上条件不成立 则施行下面语句                {                    Console.WriteLine("是任意三角形");                }            }            Console.Read();        }    }}

输出:  

                        


总结:

更加灵活使用if....else语句判断多分支条件


0 0
原创粉丝点击