Calculate the circumference and area of a circle for the given radius C++ program example
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows XP Pro SP2
Header file: Standard
Additional project setting: Set project to be compiled as C++
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)
Other info:
To do: Calculate the circumference and area of circle for the given radius in C++ programming
To show: How to calculate the circle areas and circumference if radius is given, C++ operators, operands, variables and data types
// to calculate the circumference and area of circle
#include <iostream>
using namespace std;
// define identifier PI with a constant
#define PI 3.14159
// define identifier TWO with a constant
#define TWO 2.0
int main(void)
{
float area, circumference, radius;
cout<<"\nEnter a radius of the circle in meter: ";
cin>>radius;
// circle area = PI*radius*radius
area = PI * radius * radius;
// circumference = 2*PI*radius
circumference = TWO * PI * radius;
// circle circumference
cout<<"\nCircumference = "<<circumference<<" meter";
// circle area
cout<<"\nCircle area = "<<area<<" square meter"<<endl;
return 0;
}
Output example:
Enter a radius of the circle in meter: 4.50
Circumference = 28.2743 meter
Circle area = 63.6172 square meter
Press any key to continue . . .