C++ Program to Calculate Area and Circumference of Circle
The area of a circle is the number of square units inside that circle. The formula for calculation of area of circle is:
In above formula, “r” shows the radius of circle while “π” is a Greek letter pronounced as PI. it is a ratio of circumference of a circle to the diameter. its value is constant which is 3.14.
The circumference of a circle is the distance around that circle. The formula for calculation of circumference is:
Circumference = 2πr
C++ Code to Calculate Area and Circumference of Circle:
using namespace std;
cout<<"*Calculate Area and Circumference of circle*"<<endl;
cout<<"Enter radius of circle: ";
cout<<"Area of circle: "<<area<<endl;
cout<<"Circumference of circle: "<<circum;
The above program is used to calculate the area and circumference of a circle for a given radius.
This program is based upon float type variables as we want the program to work with numbers containing decimal points. First we declared PI variable and initialized it to 3.14 so it will work as constant for whole program. Then we declared three more variables. One for user input and two for storing results.
Recommended reading: Program To Find Area and Perimeter of Rectangle in C++
As program starts its execution, it asks the user to enter the radius of circle and stores the input in float type variable radius. After that it calculates area and circumference of circle. In the form of C++ coding, the formulae for area and circumference of circle are as follows:
Area = π*r*r
Circumference = 2*π*r
If you liked this article, then please consider sharing it with your friends and leaving a comment below.
You can also Click Here To Download Exercise Files.