📌  相关文章
📜  查找第N个霍格本数字

📅  最后修改于: 2021-04-23 06:53:03             🧑  作者: Mango

给定数字N ,任务是打印第NHogben数字

例子:

方法:
从霍格本数的序列可以看出,第N霍格本数H N等于(N^2 - N + 1)

下面是上述方法的实现。

C++
// C++ program to print
// N-th Hogben Number
  
#include 
using namespace std;
  
// Function returns N-th
// Hogben Number
int HogbenNumber(int a)
{
    int p = (pow(a, 2) - a + 1);
    return p;
}
  
// Driver code
int main()
{
    int N = 10;
  
    cout << HogbenNumber(N);
  
    return 0;
}


Java
// Java program to print
// N-th Hogben Number
import java.util.*;
  
class GFG{
      
// Function returns N-th
// Hogben Number
public static int HogbenNumber(int a)
{
    int p = (int)(Math.pow(a, 2) - a + 1);
    return p;
}
  
// Driver code
public static void main(String args[])
{
    int N = 10;
  
    System.out.print(HogbenNumber(N));
}
}
  
// This code is contributed by Akanksha_Rai


Python3
# Python3 program to print
# N-th Hogben Number
  
# Function returns N-th
# Hogben Number
def HogbenNumber(a):
      
    p = (pow(a, 2) - a + 1)
    return p
  
# Driver code
N = 10
  
print(HogbenNumber(N))
  
# This code is contributed by shubhamsingh10


C#
// C# program to print
// N-th Hogben Number
using System;
class GFG{
      
// Function returns N-th
// Hogben Number
public static int HogbenNumber(int a)
{
    int p = (int)(Math.Pow(a, 2) - a + 1);
    return p;
}
  
// Driver code
public static void Main()
{
    int N = 10;
  
    Console.Write(HogbenNumber(N));
}
}
  
// This code is contributed by Code_Mech


输出:
91