Site icon TestingDocs.com

C++ Program to Compute Circumference of a Circle

Overview

In this tutorial, we will write a sample C++ program to compute the Area & Circumference of a Circle. We will use Code::Blocks IDE on the Windows platform.

C++ Code

In this example, we will take the user input for the circle radius, the program computes the area and circumference of the circle, displays the output to the console screen.

 

//Compute area and circumference of circle
#include<iostream>
using namespace std;
const double PI=3.1415;

int main()
{
    double radius=0.0;
    cout << "Enter circle radius :";
    cin >> radius;
    double area= PI*radius*radius;
    double circumference= 2*PI*radius;
    cout << "Area of circle =: " << area << endl;
    cout << "Circumference of circle =: "
 << circumference << endl;
    return 0;
}

Sample output

Run the program and enter sample input. Verify the output of the program.

Enter circle radius :5.0
Area of circle =: 78.5375
Circumference of circle =: 31.415

Screenshot

That’s it.

The IDE used in the program is Code:: Blocks. To download and install Code Blocks follow the link:
https://www.testingdocs.com/download-and-install-codeblocks/

For more information on Code Blocks IDE, visit the official website of Code blocks IDE:
http://www.codeblocks.org/

 

Exit mobile version