

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use the PI constant in C++?
Here we will see how to use the PI constant in C++ program. The PI constant is present in the cmath header file. The name of the constant is M_PI. We can simply include that header file, and use the constant to perform operation.
In the following example we will see how to find area of a circle using PI constant.
Example Code
#include <iostream> #include <cmath> using namespace std; float area(int radius) { return M_PI * (radius * radius); } int main () { cout << "Area of a circle with radius 7 unit is: " << area(7); }
Output
Area of a circle with radius 7 unit is: 153.938
- Related Questions & Answers
- How to get the value of PI in JavaScript?
- How to use constant in ABAP program which has trailing space?
- pi() function in PHP
- PHP pi() Function
- Arduino Uno vs Raspberry Pi
- How to set axis ticks in multiples of pi in Python Matplotlib?
- Raspberry pi hacks 8 of the most amazing ones
- How to declare and initialize constant strings in C#?
- Integrating Sharepoint with SAP using PI system
- Difference between SAP PI/PO and ESB
- FILTER_VALIDATE_BOOLEAN constant in PHP
- FILTER_VALIDATE_EMAIL constant in PHP
- FILTER_VALIDATE_FLOAT constant in PHP
- FILTER_VALIDATE_INT constant in PHP
- FILTER_VALIDATE_IP constant in PHP
Advertisements