C++ Program to compute the area and circumference of a circle


October 20, 2023, Learn eTutorial
3515

How to calculate the area and circumference of a circle, given radius?

The area of a circle is the space that the circle's closed shape takes, It can be calculated by using a formula.

Area = π r2  or area = 3.14*r*r

where

  • the value of π is 3.14.
  • r indicates the radius

The perimeter or the circumference is the circle's boundary length.

The perimeter = 2 π r or can be written as pi D

where,

  •  r = radius
  • D = diameter
find area of a circle with given radius

How to find the Area and perimeter of a circle using C++?

In the C++ program, Start with the user entering the value of the radius of the circle. Read the value to a variable r. Then calculate the area using the formula given above  Area = 3.14 * r * r, Now display the value of Area.

Calculate the value of the perimeter using the formula Perimeter = 2 * 3.14 * r Finally display the value of the perimeter for the user. 

Algorithm

Step 1:  Call the header file iostream.

Step 2: Use the namespace std.

Step 3: Open the 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 the 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
 

C++ Source Code

                                          #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;
}
                                      

OUTPUT

Enter the Radius of Circle: 6
Area of Circle = 113.04

Circumference of Circle = 37.68