In C language, use the following formulas to calculate the circumference and area of a circle: circumference = 2 π radius, area = π * radius ^ 2.
How to calculate the circumference and area of a circle using C language
In C language, you can use the following formula Calculate the circumference and area of a circle:
Perimeter
<code>周长 = 2 * π * 半径</code>
Area
<code>面积 = π * 半径 ^ 2</code>
Where, π (pi) is A constant of approximately 3.14159.
Implementation code
The following is a C language sample code for calculating the circumference and area of a circle:
<code class="c">#include <stdio.h> int main() { // 定义圆的半径 float radius; // 提示用户输入半径 printf("请输入圆的半径:"); scanf("%f", &radius); // 计算圆的周长和面积 float circumference = 2 * 3.14159 * radius; float area = 3.14159 * radius * radius; // 打印结果 printf("圆的周长:%.2f\n", circumference); printf("圆的面积:%.2f\n", area); return 0; }</code>
Sample output
<code>请输入圆的半径:10 圆的周长:62.83 圆的面积:314.16</code>
The above is the detailed content of How to find the circumference and area of a circle in c language. For more information, please follow other related articles on the PHP Chinese website!