Home  >  Article  >  Backend Development  >  How to find the circumference and area of ​​a circle in c language

How to find the circumference and area of ​​a circle in c language

下次还敢
下次还敢Original
2024-05-02 17:36:31923browse

In C language, use the following formulas to calculate the circumference and area of ​​a circle: circumference = 2 π radius, area = π * radius ^ 2.

How to find the circumference and area of ​​a circle in c language

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn