Related Articles
Program to check if N is a Hendecagonal Number
• Last Updated : 23 Mar, 2021

Given an integer N, the task is to check if N is a Hendecagonal Number or not. If the number N is an Hendecagonal Number then print “Yes” else print “No”.

Hendecagonal Number is a figurate number that extends the concept of triangular and square numbers to the decagon(11-sided polygon). The nth hendecagonal number counts the number of dots in a pattern of n nested decagons, all sharing a common corner, where the ith hendecagon in the pattern has sides made of i dots spaced one unit apart from each other. The first few hendecagonal numbers are 1, 11, 30, 58, 95, 141…

Examples:

Input: N = 11
Output: Yes
Explanation:
Second hendecagonal number is 11.
Input: N = 40
Output: No

Approach:

1. The Kth term of the Hendecagonal Number is given as

2. As we have to check that the given number can be expressed as a Hendecagonal Number or not. This can be checked as:

=>
=>

1.
2. If the value of K calculated using the above formula is an integer, then N is a Hendecagonal Number.
3. Else N is not a Hendecagonal Number.

Below is the implementation of the above approach:

## C++

 // C++ program for the above approach#include using namespace std; // Function to check if N is a// Hendecagonal Numberbool ishendecagonal(int N){    float n        = (7 + sqrt(72 * N + 49))          / 18;     // Condition to check if the    // number is a hendecagonal number    return (n - (int)n) == 0;} // Driver Codeint main(){    // Given Number    int N = 11;     // Function call    if (ishendecagonal(N)) {        cout << "Yes";    }    else {        cout << "No";    }    return 0;}

## Java

 // Java program for the above approachimport java.lang.Math; class GFG{     // Function to check if N is a// hendecagonal numberpublic static boolean ishendecagonal(int N){    double n = (7 + Math.sqrt(72 * N + 49)) / 18;         // Condition to check if the    // number is a hendecagonal number    return (n - (int)n) == 0;} // Driver code   public static void main(String[] args){             // Given number    int N = 11;         // Function call    if (ishendecagonal(N))    {        System.out.println("Yes");    }    else    {        System.out.println("No");    }}} // This code is contributed by divyeshrabadiya07

## Python3

 # Python3 program for the above approachimport math # Function to check if N is a# Hendecagonal Numberdef ishendecagonal(N):     n = (7 + math.sqrt(72 * N + 49))// 18;     # Condition to check if the    # number is a hendecagonal number    return (n - int(n)) == 0; # Driver Code # Given NumberN = 11; # Function callif (ishendecagonal(N)):    print("Yes");else:    print("No"); # This code is contributed by Nidhi_biet

## C#

 // C# program for the above approachusing System;class GFG{     // Function to check if N is a// hendecagonal numberpublic static bool ishendecagonal(int N){    double n = (7 + Math.Sqrt(72 * N + 49)) / 18;         // Condition to check if the    // number is a hendecagonal number    return (n - (int)n) == 0;} // Driver codepublic static void Main(string[] args){             // Given number    int N = 11;         // Function call    if (ishendecagonal(N))    {        Console.Write("Yes");    }    else    {        Console.Write("No\n");    }}} // This code is contributed by rutvik_56

## Javascript

 
Output:
Yes

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

In case you wish to attend live classes with industry experts, please refer Geeks Classes Live

My Personal Notes arrow_drop_up