C 语言程序:求出圆形的面积?
面积是一个表示二维图形范围的数量。圆的面积是在二维平面上由圆覆盖的面积。
要找到圆的面积,需要半径[r] 或直径[d](2* 半径)。
用于计算面积的公式为 (π*r2) 或 {(π*d2)/4}.
示例代码
使用半径找到圆的面积。
#include <stdio.h>
int main(void) {
float pie = 3.14;
int radius = 6;
printf("The radius of the circle is %d
" , radius);
float area = (float)(pie* radius * radius);
printf("The area of the given circle is %f", area);
return 0;
}输出
The radius of the circle is 6 The area of the given circle is 113.040001
示例代码
使用 math.h 库找到圆的面积,使用半径。它使用 math 类的 pow 函数找到给定数字的平方。
#include <stdio.h>
int main(void) {
float pie = 3.14;
int radius = 6;
printf("The radius of the circle is %d
" , radius);
float area = (float)(pie* (pow(radius,2)));
printf("The area of the given circle is %f", area);
return 0;
}输出
The radius of the circle is 6 The area of the given circle is 113.040001
示例代码
使用直径找到圆的面积。
#include <stdio.h>
int main(void) {
float pie = 3.14;
int Diameter = 12;
printf("The Diameter of the circle is %d
" , Diameter);
float area = (float)((pie* Diameter * Diameter)/4);
printf("The area of the given circle is %f", area);
return 0;
}输出
The Diameter of the circle is 12 The area of the given circle is 113.040001
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP