Diagonal of a Regular Heptagon in C++ Program

In this tutorial, we are going to learn how to find the diagonal of a regular heptagon.

We have to find the length of the diagonal of the regular heptagon using the given side. The length of the diagonal of a regular heptagon is 1.802 * s where s is the side of the heptagon.


Let's see the code.

 Live Demo

#include <bits/stdc++.h>
using namespace std;
float heptagonDiagonal(float s) {
   if (s < 0) {
      return -1;
   return 1.802 * s;
int main() {
   float s = 7;
   cout << heptagonDiagonal(s) << endl;
   return 0;


If you run the above code, then you will get the following result.



If you have any queries in the tutorial, mention them in the comment section.