C++ Program to calculate the area of a circle

Finding the Area of  circle in C++ :-

Here we will discuss how to find the area of a circle when its radius is given using c++ programming language.

The area of a circle can be found by using the formula:
Area of circle= 𝝅R2 ,
where R is the radius of the circle and 𝝅 has a value of 3.14
To find the area of any circle we just need to know its radius as the value of 𝝅(pi) is fixed, so using the above mentioned formula in the cpp coding.

Area of circle in C++

Working:-

  • User gives an input
  • The input is stored in a float type variable say rad.
  • Another float type variable is taken say circleArea.
  • Now using the formula we find the area of the circle of radius rad and store it in circleArea.

                          circleArea= 3.14* rad* rad;

  • Print the value of circleArea.
Area of circle

C++ Code:-

//C++ Program
// area of circle
#include<iostream>
using namespace std;
int main()
{
    float rad;
    cout<<"Enter the radius: ";
    cin>>rad;
    float circleArea = 3.14 * rad * rad;
    cout<<"Area of the circle of radius "<<rad<<"  is "<<circleArea;
    return 0;
}
Output:
Enter the radius: 7
Area of the circle of radius 7 is 153.86

Algorithm using diameter :-

  • User gives an input (diameter of the circle)
  • The input is stored in a float type variable say d.
  • Another float type variable is taken say circleArea.
  • Now using the formula we find the area of the circle of diameter d and store it in circleArea.

                          circleArea= (3.14* d* d)/4;

  • Print the value of circleArea.

C++ Code:-

//C++ Program
// area of circle
#include<iostream>
using namespace std;
int main()
{
    float d;
    cout<<"Enter the diameter: ";
    cin>>d;
    float circleArea = (3.14 * d * d)/4;
    cout<<"Area of the circle of diameter "<<d<<"  is "<<circleArea;
    return 0;
}
Output:
Enter the diameter: 14
Area of the circle of diameter 14 is 153.86