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

Updated on: 09-Jul-2020

57 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements