C++程序:计算两个同心圆之间的面积?


什么是同心圆?

同心圆是指内含于另一个圆内的圆,这意味着它们共享同一个圆心,但半径长度不同,即r1和r2,其中r2>r1。两个同心圆之间的区域称为环形区域。

下图是同心圆的图形

问题

给定两个半径分别为r1和r2的不同同心圆,其中r2>r1。任务是找到两个圆之间的面积,该面积用蓝色突出显示。

要计算两个圆之间的面积,我们可以从较大的圆的面积中减去较小的圆的面积。

假设,较大的圆的半径为r2,较小的圆的半径为r1,则

示例

Input-: r1=3 r2=4
Output-: area between two given concentric circle is :21.98

算法

Start
Step 1 -> define macro as
   #define pi 3.14
Step 2 -> Declare function to find area between the two given concentric circles
   double calculateArea(int x, int y)
   set double outer = pi * x * x
   Set double inner = pi * y * y
return outer-inner
step 3 -> In main()
   Declare variable as int x = 4 and int y = 3
   Print calculateArea(x,y)
Stop

示例

#include <bits/stdc++.h>
#define pi 3.14
using namespace std;
// Function to find area between the two given concentric circles
double calculateArea(int x, int y){
   double outer = pi * x * x;
   double inner = pi * y * y;
   return outer-inner;
}
int main(){
   int x = 4;
   int y = 3;
   cout <<"area between two given concentric circle is :"<<calculateArea(x, y);
   return 0;
}

输出

area between two given concentric circle is :21.98

更新于:2019年9月20日

379 次浏览

开启你的职业生涯

通过完成课程获得认证

开始学习
广告
© . All rights reserved.