- 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
C++ program to find the side of the Octagon inscribed within the square
In this tutorial, we will be discussing a program to find the side of the octagon inscribed within a given square.
For this, we will be given with the side of a square and our task is to find the side of the largest octagon that can be inscribed in it.
Finding the relation between the sides of the square and the octagon, we find the formula for the side of the octagon
side of square/(√2 + 1)
Example
#include <bits/stdc++.h> using namespace std; //calculating the side of the octagon float calc_oside(float a) { if (a < 0) return -1; float s = a / (sqrt(2) + 1); return s; } int main() { float a = 41; cout << calc_oside(a) << endl; return 0; }
Output
16.9828
Advertisements
To Continue Learning Please Login
Login with Google