C++ 中计算半圆的面积和周长的程序
在这个问题中,我们给出一个值表示一个半圆的半径。我们的任务是创建一个在 C++ 中计算半圆的面积和周长的程序。
半圆是一个闭合图形,是圆的一半。

让我们举一个例子来理解这个问题,
输入
R = 5
输出
area = 39.25 perimeter = 15.7
解决方案途径
为了解决这个问题,我们将使用半圆的面积和周长的数学公式,该公式是将圆的面积除以 2 得出的。
半圆面积,A = $½(π*a^2)=1.571*a^2$
半圆周长,P =(π*a)
半圆面积,面积 = $½(π*a^2)$
示例程序来说明解决方案的工作原理
示例
#include <iostream>
using namespace std;
float calaAreaSemi(float R) {
return (1.571 * R * R);
}
float calaPeriSemi(float R) {
return (3.142 * R);
}
int main(){
float R = 5;
cout<<"The radius of semicircle is "<<R<<endl;
cout<<"The area of semicircle is "<<calaAreaSemi(R)<<endl;
cout<<"The perimeter of semicircle is "<<calaPeriSemi(R)<<endl;
return 0;
}输出
The radius of semicircle is 5 The area of semicircle is 39.275 The perimeter of semicircle is 15.71
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP