计算圆周的面积
主题: 输入圆的半径. 计算圆的周长和面积
主题相当明确,并没有什么可讨论更多. 事情你要做的就是记住一个圆的周长和面积公式. 我有以下公式:
P = 2πR S = πR²
所以公式有. 现在我们只码公式.
/*
* Calculator P and S of Circle
*/
#include <stdio.h>
#include <math.h>
int main() {
float r, p, s;
printf("Enter r = ");
scanf("%f", &r);
p = 2 * M_PI * r;
s = M_PI * r * r;
printf("Perimeter of circle = %f\n", p );
printf("Acreage of circle = %f\n", s );
return 0;
}
在上面的代码, 你发现自己使用的库文件math.h提供恒定的M_PI是精度高.
从上面所有, 你做下面的练习.
锻炼: 计算周长和面积 10 圈,但只有使用单 1 R是转弯半径



最新评论