Home > Backend Development > C++ > 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

下次还敢
Release: 2024-05-02 17:36:31
Original
956 people have browsed it

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>
Copy after login

Area

<code>面积 = π * 半径 ^ 2</code>
Copy after login

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>
Copy after login

Sample output

<code>请输入圆的半径:10
圆的周长:62.83
圆的面积:314.16</code>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template