《21天学通C#》第一节题目。计算圆的面积和表面积

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

namespace _1_计算圆的面积和表面积_
{
class Program
{
static void Main(string[] args)
{
//Declare variables
bool IsTrue = true;

int radius=0;
while (IsTrue)
{
Console.WriteLine("请输入半径:");
string input_radius = Console.ReadLine();

if (!int.TryParse(input_radius, out radius))
{
Console.WriteLine("请输入正确的半径!");
}
else
{
IsTrue = false;
}
}

const double PI = 3.14159;
double circum, area;

//Do caiculations
area = PI * radius * radius;
circum = 2 * PI * radius;

//Print the result
Console.WriteLine("Radius={0},PI={1}", radius, PI);
Console.WriteLine("This area is {0}", area);
Console.WriteLine("The circumference is {0}", circum);
Console.WriteLine("请按任意键退出程序!");
Console.ReadKey();

}
}
}

posted on 2018-11-05 14:13  天源  阅读(272)  评论(0编辑  收藏  举报

导航