csharp进阶练习题:计算半径为r的圆内正n边形的面积【难度:2级】:
编写以下功能:
功能areaOfPolygonInsideCircle(circleRadius,numberOfSides)
功能areaOfPolygonInsideCircle($ circleRadius,$ numberOfSides)
公共静态双AreaOfPolygonInsideCircle(双circleRadius,INT numberOfSides)
DEF area_of_polygon_inside_circle(circle_radius,number_of_sides):
DEF area_of_polygon_inside_circle(circle_radius,number_of_sides)
晶
DEF area_of_polygon_inside_circle(circle_radius,number_of_sides)
常规
静态双areaOfPolygonInsideCircle(circleRadius,numberOfSides)
双areaOfPolygonInsideCircle(双circleRadius,INT numberOfSides)
areaOfPolygonInsideCircle(_ circleRadius:双,_ numberOfSides:智力) - >双
objc
双area_of_polygon_inside_circle(双circle_radius,INT number_of_sides);
areaOfPolygonInsideCircle =(circleRadius,numberOfSides)
导出功能areaOfPolygonInsideCircle(circleRadius:编号,numberOfSides:号码):序号
公共静态双areaOfPolygonInsideCircle(双circleRadius,INT numberOfSides)
应该计算半径的圆circleRadius
或circle_radius
穿过多边形的所有顶点通过(例如圆被称为** 外接圆内numberOfSides或
number_of_sides边
正多边形的面积* * 或** 外接圆**).答案应该是四舍五入至小数点后3位的数字.
输入输出::例子
areaOfPolygonInsideCircle(3,3)//返回11.691
areaOfPolygonInsideCircle(5.8,7)//返回92.053
areaOfPolygonInsideCircle(4,5)//返回38.042
areaOfPolygonInsideCircle(3,3)//返回11.691
areaOfPolygonInsideCircle(5.8,7)//返回92.053
areaOfPolygonInsideCircle(4,5)//返回38.042
areaOfPolygonInsideCircle(3,3)//返回11.691
areaOfPolygonInsideCircle(5.8,7)//返回92.053
areaOfPolygonInsideCircle(4,5)//返回38.042
常规
areaOfPolygonInsideCircle(3,3)//返回11.691
areaOfPolygonInsideCircle(5.8,7)//返回92.053
areaOfPolygonInsideCircle(4,5)//返回38.042
AreaOfPolygonInsideCircle(3,3)//返回11.691
AreaOfPolygonInsideCircle(5.8,7)//返回92.053
AreaOfPolygonInsideCircle(4,5)//返回38.042
area_of_polygon_inside_circle(3,3)# 返回11.691
area_of_polygon_inside_circle(5.8,7)# 返回92.053
area_of_polygon_inside_circle(4,5)# 返回38.042
objc
area_of_polygon_inside_circle(3,3); // => 11.691
area_of_polygon_inside_circle(5.8,7); // => 92.053
area_of_polygon_inside_circle(4,5); // => 38.042
areaOfPolygonInsideCircle(3,3); // => 11.691
areaOfPolygonInsideCircle(5.8,7); // => 92.053
areaOfPolygonInsideCircle(4,5); // => 38.042
area_of_polygon_inside_circle(3,3)# 返回11.691
area_of_polygon_inside_circle(5.8,7)# 返回92.053
area_of_polygon_inside_circle(4,5)# 返回38.042
晶
area_of_polygon_inside_circle(3,3)# 返回11.691
area_of_polygon_inside_circle(5.8,7)# 返回92.053
area_of_polygon_inside_circle(4,5)# 返回38.042
areaOfPolygonInsideCircle(3,3)# 返回11.691
areaOfPolygonInsideCircle(5.8,7)# 返回92.053
areaOfPolygonInsideCircle(4,5)# 返回38.042
areaOfPolygonInsideCircle(3,3)//返回11.691
areaOfPolygonInsideCircle(5.8,7)//返回92.053
areaOfPolygonInsideCircle(4,5)//返回38.042
areaOfPolygonInsideCircle(3,3)//返回11.691
areaOfPolygonInsideCircle(5.8,7)//返回92.053
areaOfPolygonInsideCircle(4,5)//返回38.042
编程目标:
namespace Solution {
using System;
public class Calculator {
public static double AreaOfPolygonInsideCircle(double circleRadius, int numberOfSides) {
// Your code here
}
}
}
测试样例:
namespace Solution {
using NUnit.Framework;
using System;
[TestFixture]
public class SolutionTest {
[Test]
public void ExampleTests() {
.(, .(,3));
Assert.AreEqual(8, Calculator.AreaOfPolygonInsideCircle(2,4));
Assert.AreEqual(14.86, Calculator.AreaOfPolygonInsideCircle(2.5,5));
}
}
}
最佳答案(多种解法):
更多关联题目:
免责申明
本博客所有编程题目及答案均收集自互联网,主要用于供网友学习参考,如有侵犯你的权益请联系管理员及时删除,谢谢
题目收集至https://www.codewars.com/
https://www.codewars.com/kata/calculate-the-area-of-a-regular-n-sides-polygon-inside-a-circle-of-radius-r