C language may be difficult for novices to calculate the area and circumference of a circle. But in fact, as long as you understand the calculation principles of the area and circumference of a circle, it is easy to implement.
In geometry, the area of a circle is equal to πr², and the circumference of a circle is equal to 2πr. The Greek letter π here is a constant approximately equal to 3.14159.
Recommended course: "C Language Tutorial"
Below we will introduce it to you through specific code examples. How to calculate the area and circumference of a circle in C language.
Write a C program to calculate the circumference and area of a circle with a radius of 6 inches.
The code is as follows:
#include <stdio.h> int main() { int radius; float area, perimeter; radius = 6; perimeter = 2*3.14*radius; printf("圆的周长 = %f 英寸\n", perimeter); area = 3.14*radius*radius; printf("圆的面积 = %f 平方英寸\n", area); return(0); }
The calculation result is as follows:
Why is the area of a circle multiplied by the square of the radius? ?
can be shown in the following animation:
This article is about the specific method of calculating the area and circumference of a circle in C language. I hope it will help you if you need Friends help!
The above is the detailed content of How to calculate the area and circumference of a circle in c language. For more information, please follow other related articles on the PHP Chinese website!