以下数字构成同心六边形序列:
0, 1, 6, 13, 24, 37, 54, 73, 96, 121, 150 ……
数字序列形成一个具有同心六边形的图案,数字表示该图案的第 n 级后所需的点数。
例子:
Input : N = 3
Output : 13
Input : N = 4
Output : 24
方法 :
以上系列可以参考同心六角数。
该系列的第N项是3*n 2 /2
下面是上述方法的实现:
C++
// CPP program to find nth concentric hexagon number
#include
using namespace std;
// Function to find nth concentric hexagon number
int concentric_Hexagon(int n)
{
return 3 * pow(n, 2) / 2;
}
// Driver code
int main()
{
int n = 3;
// Function call
cout << concentric_Hexagon(n);
return 0;
}
Java
// Java program to find
// nth concentric hexagon number
class GFG
{
// Function to find
// nth concentric hexagon number
static int concentric_Haxagon(int n)
{
return 3 * (int)Math.pow(n, 2) / 2;
}
// Driver Code
public static void main (String[] args)
{
int n = 3;
// Function call
System.out.println(concentric_Haxagon(n));
}
}
// This code is contributed by
// sanjeev2552
Python3
# Python3 program to find
# nth concentric hexagon number
# Function to find
# nth concentric hexagon number
def concentric_Hexagon(n):
return 3 * pow(n, 2) // 2
# Driver code
n = 3
# Function call
print(concentric_Hexagon(n))
# This code is contributed by Mohit Kumar
C#
// C# program to find nth concentric hexagon number
using System;
class GFG
{
// Function to find nth concentric hexagon number
static int concentric_Hexagon(int n)
{
return 3 * (int)Math.Pow(n, 2) / 2;
}
// Driver code
public static void Main()
{
int n = 3;
// Function call
Console.WriteLine(concentric_Hexagon(n));
}
}
// This code is contributed by Nidhi
Javascript
输出:
13