c语言圆的面积和周长的源代码,c语言求圆的面积和周长

C#程序:

using System;

class Program

{

static void Main()

{

double r;                                 //圆半径

double circle;                           //圆周长

double area;                            //圆面积

const double PI = 3.14159;      //π

Console.Write("请输入半径:");

r = double.Parse(Console.ReadLine());

circle = 2 * PI * r;        //计算圆周长

area = PI * r * r;          //计算圆面积

Console.WriteLine("半径为{0}的圆周长为{1}", r, circle);

Console.WriteLine("半径为{0}的圆周长为{1}", r, area);

}

}

运行测试:

fc0d2361d4bff565a5aa9ea038658b7f.png

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
求多边形的内切可以通过计算多边形的边界和角度来实现。下面是一个使用C语言编写的求多边形的内切的示例代码: ```c #include <stdio.h> #include <math.h> typedef struct { double x, y; } Point; // 计算两点间的距离 double distance(Point p1, Point p2) { return sqrt(pow(p2.x - p1.x, 2) + pow(p2.y - p1.y, 2)); } // 计算多边形的内切 void calculateIncircle(Point* polygon, int size) { double perimeter = 0; double centerX = 0, centerY = 0; // 计算多边形的周长和重心 for (int i = 0; i < size; i++) { perimeter += distance(polygon[i], polygon[(i + 1) % size]); centerX += polygon[i].x; centerY += polygon[i].y; } centerX /= size; centerY /= size; double inradius = perimeter / (2 * M_PI); // 内切的半径 printf("内切的半径: %.2f\n", inradius); printf("内切的中心坐标: (%.2f, %.2f)\n", centerX, centerY); } int main() { // 定义一个五边形的顶点坐标 Point polygon[] = {{1, 1}, {2, 3}, {4, 6}, {7, 5}, {8, 2}}; int size = sizeof(polygon) / sizeof(polygon[0]); calculateIncircle(polygon, size); return 0; } ``` 上述代码中,我们首先定义了一个`Point`结构体来表示点的坐标。然后,我们定义了一个`distance`函数来计算两点之间的距离。接着,我们在`calculateIncircle`函数中计算多边形的周长和重心,并根据周长计算出内切的半径。最后,我们使用`printf`函数输出内切的半径和中心坐标。 在`main`函数中,我们定义了一个五边形的顶点坐标,并调用`calculateIncircle`函数来计算内切的半径和中心坐标。运行该代码后,可以得到五边形的内切的半径和中心坐标。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值