C++ Online Compiler
Example: Procedural Circle Area in C++
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// Procedural Circle Area #include <iostream> #include <cmath> // For M_PI or custom PI definition // Define PI if not available via cmath (e.g., older compilers or specific standards) #ifndef M_PI #define M_PI 3.14159265358979323846 #endif double calculateCircleArea(double radius) { return M_PI * radius * radius; } int main() { double radius; std::cout << "Enter the radius of the circle: "; std::cin >> radius; if (radius < 0) { std::cout << "Radius cannot be negative." << std::endl; } else { double area = calculateCircleArea(radius); std::cout << "The area of the circle with radius " << radius << " is: " << area << std::endl; } return 0; }
Output
Clear
ADVERTISEMENTS