r圆怎么编程序

时间:2025-01-17 20:02:32 游戏攻略

C语言

```c

include

define PI 3.14159

int main() {

float r, c, s;

printf("请输入圆的半径r: ");

scanf("%f", &r);

c = 2 * r * PI;

s = r * r * PI;

printf("圆的周长是: %.2f\n", c);

printf("圆的面积是: %.2f\n", s);

return 0;

}

```

C++

```cpp

include

include

using namespace std;

int main() {

double r, c, s;

cout << "请输入圆的半径r: ";

cin >> r;

c = 2 * r * M_PI;

s = r * r * M_PI;

cout << "圆的周长是: "<< c << endl;

cout << "圆的面积是: "<< s << endl;

return 0;

}

```

Python

```python

import math

r = float(input("请输入圆的半径r: "))

c = 2 * r * math.pi

s = r * r * math.pi

print("圆的周长是: {:.2f}".format(c))

print("圆的面积是: {:.2f}".format(s))

```

MATLAB

```matlab

r = input('请输入圆的半径r: ');

c = 2 * r * pi;

s = r * r * pi;

disp(['圆的周长是: ', num2str(c)]);

disp(['圆的面积是: ', num2str(s)]);

```

这些程序都使用了基本的数学公式来计算圆的周长和面积,并通过用户输入获取圆的半径。你可以根据自己的需求选择合适的编程语言和环境来实现。