1. 编写程序,输入一个圆的半径,计算输出圆的面积(s=πr2), 小数点后保留两位数

2025-04-17 13:22:03
推荐回答(1个)
回答1:

public class Program
{
    private static void Main(string[] args)
    {
        try
        {
            Console.Write("请输入半径: ");
            int r = Convert.ToInt32(Console.ReadLine());
            double s = Math.PI*(Math.Pow(r, 2));
            Console.WriteLine("半径为{0}圆的面积为{1}", r, s.ToString("F"));
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }
    }
}