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

更新時間: 2019-07-30

17K+ 瀏覽量

開啟您的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.