Here, you will learn to find the area and circumference of a circle based on its radius entered by the user at run-time in C++ programming
The area of a circle is the region occupied by the circle in a two-dimensional plane. It can be determined easily using a formula. area = πr2
The value of π is 3.14. And r indicates the radius of the circle. This formula can also be written as:
area = 3.14*r*r
The perimeter or circumference of a circle is its boundary or the complete arc length of the periphery of a circle
Perimeter of a circle = 2 π r = π D units
where,
• r = radius of the circle
• D = diameter of the circle.
Ask the user to enter the value of the radius of the circle. Read the value to a variable r; Calculate the area using the formula given above
3.14 * r * r
Get the value to the variable area and display it on the screen.
Calculate the value of the perimeter of the circle
2 * 3.14 * rad;
Get the value to the variable circum and display it on the screen.
Step 1: Call the header file iostream
.
Step 2: Use the namespace std
.
Step 3: Open the integer type main function; int main().
Step 4: Declare float type variables r, area circum;
Step 5: Ask the user to enter the value of the radius of the circle.
Step 6: Get the value of radius to the variable r.
Step 7: Calculate the area using the formula 3.14 * r * r;
Step 8: Get the value to the variable area;
Step 9: Display the result;
Step 10: Calculate the circumference using the formula 2 * 3.14 * r;
Step 11: Get the value to the variable circum;
Step 12: Display the result;
Step 13: Exit
#include<iostream>
using namespace std;
int main()
{
float r, area, circum;
cout<<"Enter the Radius of Circle: ";
cin>>r;
area = 3.14*r*r;
cout<<"\nArea of Circle = "<<area;
cout<<endl;
circum = 2*3.14*r;
cout<<"\nCircumference of Circle = "<<circum;
cout<<endl;
return 0;
}
Enter the Radius of Circle: 6 Area of Circle = 113.04 Circumference of Circle = 37.68