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