C++ program to find the side of the Octagon inscribed within the square

C++Server Side ProgrammingProgramming

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
Published on 21-Nov-2019 13:03:53
Advertisements