如何在C ++中使用PI常量?
在这里,我们将看到如何在C++程序中使用PI常量。PI常数存在于cmath头文件中。该常量的名称是M_PI。我们可以简单地包含该头文件,并使用常量执行操作。
在下面的示例中,我们将看到如何使用PI常数查找圆的面积。
范例程式码
#include <iostream>
#include <cmath>
using namespace std;
float area(int radius) {
return M_PI * (radius * radius);
}
int main () {
cout << "Area of a circle with radius 7 unit is: " << area(7);
}输出结果
Area of a circle with radius 7 unit is: 153.938
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短