隐藏页面特效

C# 计算三角形和长方形 周长面积

编写一个控制台应用程序,输入三角形或者长方形边长,计算其周长和面积并输出。

 

代码如下:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Testing1_1 { class Program { static void Main(string[] args) { //三角形 长方形的变量 int i; double t1, t2, t3; double rlenth, rwidth; double cir, area; //菜单选择 Console.WriteLine("欢迎进入几何图形周长、面积计算系统"); //菜单实现 while(true) { Console.WriteLine("1、三角形 2、长方形 3、退出"); Console.WriteLine("请输入序号:"); i = int.Parse(Console.ReadLine()); switch(i) { case 1: //三角形周长及面积 Console.WriteLine("请输入第一条边长:"); t1 = float.Parse(Console.ReadLine()); Console.WriteLine("请输入第二条边长:"); t2 = float.Parse(Console.ReadLine()); Console.WriteLine("请输入第三条边长:"); t3 = float.Parse(Console.ReadLine()); cir = t1 + t2 + t3; //三角形周长 area = Math.Sqrt(cir / 2 * (cir / 2 - t1) * (cir / 2 - t2) * (cir / 2 - t3)); //三角形面积 Console.WriteLine("三角形周长为:{0}", cir); Console.WriteLine("三角形面积为:{0}", area); break; case 2: //长方形周长及面积 Console.WriteLine("请输入长方形的长:"); rlenth = float.Parse(Console.ReadLine()); Console.WriteLine("请输入长方形的宽:"); rwidth = float.Parse(Console.ReadLine()); cir = 2 * (rlenth + rwidth); area = rlenth * rwidth; Console.WriteLine("长方形周长为:{0}", cir); Console.WriteLine("长方形面积为:{0}", area); break; case 3: Console.WriteLine("欢迎您下次进入!!"); break; default: Console.WriteLine("输入错误!!!!"); break; } if (i == 3) { break; } } } } }


__EOF__

本文作者往心。
本文链接https://www.cnblogs.com/lx06/p/15686180.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   往心。  阅读(639)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· AI与.NET技术实操系列(六):基于图像分类模型对图像进行分类
历史上的今天:
2020-12-14 jsp标签问题
点击右上角即可分享
微信分享提示