C++ Online Compiler
Example: How to Find Area of a Circle with Diameter in C++ using the M_PI constant
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// How to Find Area of a Circle with Diameter in C++ using the M_PI constant #include <iostream> #include <cmath> using namespace std; int main() { float r, d = 0, c = 0, a = 0; // r is the radius of the circle // d is the diameter of the circle // c is the circumference of the circle // a is the area of the circle cout << "Enter the radius of the circle::\n"; cin >> r; // It will calculate the diameter, circumference, and area of the circle d = 2 * r; c = 2 * M_PI * r; a = M_PI * (r * r); // It will produce the final output cout << "\n"; cout << "Diameter :: = " << d << " units\n"; cout << "Circumference :: = " << c << " units\n"; cout << "Area :: = " << a << " sq. units\n"; return 0; }
7
Output
Clear
ADVERTISEMENTS