![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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
Advertisements