c# 函数重载 示例 求圆的面积 -尊龙游戏旗舰厅官网
尊龙游戏旗舰厅官网
收集整理的这篇文章主要介绍了
c# 函数重载 示例 求圆的面积
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
using system;
using system.collections.generic;
using system.linq;
using system.text;
namespace consoleapplication
{
class circle
{
private const float pi = 3.141526f;
//1.没有任何已知条件
public static double area()
{
console.writeline("空空如也!");
return 0;
}
//2.已知圆心坐标
public static double area(int x1, int y1)
{
console.writeline("这是一个圆点,坐标为({0},{1})",x1,y1);
return 0;
}
//3.已知半径
public static double area(double r)
{
double thearea;
thearea = pi * r * r;
return thearea;
}
//4.已知圆心坐标和半径
public static double area(int x1, int y1, double r)
{
console.writeline("这是一个圆点在({0},{1})半径为{2}的圆", x1, y1, r);
return area(r);
}
//5.已知圆心和圆周边上的一点
public static double area(int x1, int y1, int x2, int y2)
{
int x = x2 - x1;
int y = y2 - y2;
double r = (double)math.sqrt(x*xy*y);
console.writeline("这是一个圆心在({0},{1}),圆周边一点在({2},{3})的圆,圆的半径为{4}",x1,y1,x2,y2,r);
return area(r);
}
static void main(string[] args)
{
int x1=2,x2=4; //x坐标
int y1=3,y2=5; //y坐标
double radius=3; //半径
double circlearea = 0;
circlearea = area();
console.writeline("-->1.面积为{0}",circlearea);
console.writeline();
circlearea = area(x1,y1);
console.writeline("-->2.面积为{0}", circlearea);
console.writeline();
circlearea = area(radius);
console.writeline("-->3.面积为{0}", circlearea);
console.writeline();
circlearea = area(x1, y1, radius);
console.writeline("-->4.面积为{0}", circlearea);
console.writeline();
circlearea = area(x1, y1, x2, y2);
console.writeline("-->5.面积为{0}", circlearea);
console.writeline();
console.readkey();
}
}
}
using system.collections.generic;
using system.linq;
using system.text;
namespace consoleapplication
{
class circle
{
private const float pi = 3.141526f;
//1.没有任何已知条件
public static double area()
{
console.writeline("空空如也!");
return 0;
}
//2.已知圆心坐标
public static double area(int x1, int y1)
{
console.writeline("这是一个圆点,坐标为({0},{1})",x1,y1);
return 0;
}
//3.已知半径
public static double area(double r)
{
double thearea;
thearea = pi * r * r;
return thearea;
}
//4.已知圆心坐标和半径
public static double area(int x1, int y1, double r)
{
console.writeline("这是一个圆点在({0},{1})半径为{2}的圆", x1, y1, r);
return area(r);
}
//5.已知圆心和圆周边上的一点
public static double area(int x1, int y1, int x2, int y2)
{
int x = x2 - x1;
int y = y2 - y2;
double r = (double)math.sqrt(x*xy*y);
console.writeline("这是一个圆心在({0},{1}),圆周边一点在({2},{3})的圆,圆的半径为{4}",x1,y1,x2,y2,r);
return area(r);
}
static void main(string[] args)
{
int x1=2,x2=4; //x坐标
int y1=3,y2=5; //y坐标
double radius=3; //半径
double circlearea = 0;
circlearea = area();
console.writeline("-->1.面积为{0}",circlearea);
console.writeline();
circlearea = area(x1,y1);
console.writeline("-->2.面积为{0}", circlearea);
console.writeline();
circlearea = area(radius);
console.writeline("-->3.面积为{0}", circlearea);
console.writeline();
circlearea = area(x1, y1, radius);
console.writeline("-->4.面积为{0}", circlearea);
console.writeline();
circlearea = area(x1, y1, x2, y2);
console.writeline("-->5.面积为{0}", circlearea);
console.writeline();
console.readkey();
}
}
}
转载于:https://www.cnblogs.com/zhangzufa/archive/2009/04/01/1427370.html
总结
以上是尊龙游戏旗舰厅官网为你收集整理的c# 函数重载 示例 求圆的面积的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: sql server 2005学习笔记
- 下一篇: