Posted on by Kalkicode
Code Mathematics

Determine that if given number is full Fibonacci Number

A full Fibonacci number is a positive integer that can be written as the sum of two or more consecutive Fibonacci numbers. To determine if a given number is a full Fibonacci number, we can check if it can be expressed as the sum of two or more consecutive Fibonacci numbers. If it can, then it is a full Fibonacci number; otherwise, it is not. Fibonacci numbers are a sequence of numbers in which each number is the sum of the two preceding numbers, starting from 0 and 1.

Fibonacci numbers are a sequence of numbers in which each number is the sum of the two preceding numbers, starting from 0 and 1. So the sequence begins 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, and so on.

To determine if a given number is a full Fibonacci number, we need to check if it can be expressed as the sum of two or more consecutive Fibonacci numbers. For example, the number 21 is a full Fibonacci number because it can be expressed as the sum of 8 and 13, two consecutive Fibonacci numbers.

Program Solution

``````//  C program for
//  Determine that if given number is full Fibonacci Number
#include <stdio.h>
#include <math.h>

int isFibonacciNo(int n)
{
//  5n²+4
int a = 5 *n *n + 4;
//  5n²-4
int b = 5 * n * n - 4;
int aSqrt = sqrt(a);
int bSqrt = sqrt(b);
if ((aSqrt *aSqrt) == a || (bSqrt *bSqrt) == b)
{
// When aSqrt or bSqrt is perfect square
return 1;
}
return 0;
}
int isFibonacciDigit(int num)
{
int n = num;
while (n > 0)
{
if (n % 10 == 4 && n % 10 == 6 &&
n % 10 == 7 && n % 10 == 9)
{
// When digit is not [1 2 3 5 8]
// Is not fibonacci digit
return 0;
}
// Remove last digit
n = n / 10;
}
return 1;
}
void isFullFibonacciNo(int n)
{
if (n > 0 && isFibonacciNo(n) && isFibonacciDigit(n))
{
// ➀ When number Fibonacci and
// ➁ When all digits of number is Fibonacci
printf("\n Given %d is full fibonacci number ", n);
}
else
{
printf("\n Given %d is not fibonacci number ", n);
}
}
int main(int argc, char const *argv[])
{
// Test
isFullFibonacciNo(51);
isFullFibonacciNo(233);
isFullFibonacciNo(21);
isFullFibonacciNo(14);
return 0;
}``````

Output

`````` Given 51 is not fibonacci number
Given 233 is full fibonacci number
Given 21 is full fibonacci number
Given 14 is not fibonacci number``````
``````// Java Program
// Determine that if given number is full Fibonacci Number
public class FibonacciNumber
{
public boolean isFibonacciNo(int n)
{
//  5n²+4
int a = 5 * n * n + 4;
//  5n²-4
int b = 5 * n * n - 4;
int aSqrt = (int)Math.sqrt(a);
int bSqrt = (int)Math.sqrt(b);
if ((aSqrt * aSqrt) == a || (bSqrt * bSqrt) == b)
{
// When aSqrt or bSqrt is perfect square
return true;
}
return false;
}
public boolean isFibonacciDigit(int num)
{
int n = num;
while (n > 0)
{
if (n % 10 == 4 && n % 10 == 6 && n % 10 == 7 && n % 10 == 9)
{
// When digit is not [1 2 3 5 8]
// Is not fibonacci digit
return false;
}
// Remove last digit
n = n / 10;
}
return true;
}
public void isFullFibonacciNo(int n)
{
if (n > 0 && isFibonacciNo(n) && isFibonacciDigit(n))
{
// ➀ When number Fibonacci and
// ➁ When all digits of number is Fibonacci
System.out.print("\n Given " + n + " is full fibonacci number ");
}
else
{
System.out.print("\n Given " + n + " is not fibonacci number ");
}
}
public static void main(String[] args)
{
// Test
}
}``````

Output

`````` Given 51 is not fibonacci number
Given 233 is full fibonacci number
Given 21 is full fibonacci number
Given 14 is not fibonacci number``````
``````// Include header file
#include <iostream>
#include <math.h>

using namespace std;
// C++ Program
// Determine that if given number is full Fibonacci Number
class FibonacciNumber
{
public: bool isFibonacciNo(int n)
{
//  5n²+4
int a = 5 *n *n + 4;
//  5n²-4
int b = 5 *n *n - 4;
int aSqrt = (int) sqrt(a);
int bSqrt = (int) sqrt(b);
if ((aSqrt *aSqrt) == a || (bSqrt *bSqrt) == b)
{
// When aSqrt or bSqrt is perfect square
return true;
}
return false;
}
bool isFibonacciDigit(int num)
{
int n = num;
while (n > 0)
{
if (n % 10 == 4 && n % 10 == 6 &&
n % 10 == 7 && n % 10 == 9)
{
// When digit is not [1 2 3 5 8]
// Is not fibonacci digit
return false;
}
// Remove last digit
n = n / 10;
}
return true;
}
void isFullFibonacciNo(int n)
{
if (n > 0 && this->isFibonacciNo(n) && this->isFibonacciDigit(n))
{
// ➀ When number Fibonacci and
// ➁ When all digits of number is Fibonacci
cout << "\n Given " << n << " is full fibonacci number ";
}
else
{
cout << "\n Given " << n << " is not fibonacci number ";
}
}
};
int main()
{
// Test
return 0;
}``````

Output

`````` Given 51 is not fibonacci number
Given 233 is full fibonacci number
Given 21 is full fibonacci number
Given 14 is not fibonacci number``````
``````// Include namespace system
using System;
// Csharp Program
// Determine that if given number is full Fibonacci Number
public class FibonacciNumber
{
public Boolean isFibonacciNo(int n)
{
//  5n²+4
int a = 5 * n * n + 4;
//  5n²-4
int b = 5 * n * n - 4;
int aSqrt = (int) Math.Sqrt(a);
int bSqrt = (int) Math.Sqrt(b);
if ((aSqrt * aSqrt) == a || (bSqrt * bSqrt) == b)
{
// When aSqrt or bSqrt is perfect square
return true;
}
return false;
}
public Boolean isFibonacciDigit(int num)
{
int n = num;
while (n > 0)
{
if (n % 10 == 4 && n % 10 == 6 &&
n % 10 == 7 && n % 10 == 9)
{
// When digit is not [1 2 3 5 8]
// Is not fibonacci digit
return false;
}
// Remove last digit
n = n / 10;
}
return true;
}
public void isFullFibonacciNo(int n)
{
if (n > 0 && this.isFibonacciNo(n) && this.isFibonacciDigit(n))
{
// ➀ When number Fibonacci and
// ➁ When all digits of number is Fibonacci
Console.Write("\n Given " + n + " is full fibonacci number ");
}
else
{
Console.Write("\n Given " + n + " is not fibonacci number ");
}
}
public static void Main(String[] args)
{
// Test
}
}``````

Output

`````` Given 51 is not fibonacci number
Given 233 is full fibonacci number
Given 21 is full fibonacci number
Given 14 is not fibonacci number``````
``````package main
import "math"
import "fmt"
// Go Program
// Determine that if given number is full Fibonacci Number

func isFibonacciNo(n int) bool {
//  5n²+4
var a int = 5 * n * n + 4
//  5n²-4
var b int = 5 * n * n - 4
var aSqrt int = int(math.Sqrt(float64(a)))
var bSqrt int = int(math.Sqrt(float64(b)))
if (aSqrt * aSqrt) == a || (bSqrt * bSqrt) == b {
// When aSqrt or bSqrt is perfect square
return true
}
return false
}
func isFibonacciDigit(num int) bool {
var n int = num
for (n > 0) {
if n % 10 == 4 && n % 10 == 6 &&
n % 10 == 7 && n % 10 == 9 {
// When digit is not [1 2 3 5 8]
// Is not fibonacci digit
return false
}
// Remove last digit
n = n / 10
}
return true
}
func isFullFibonacciNo(n int) {
if n > 0 && isFibonacciNo(n) && isFibonacciDigit(n) {
// ➀ When number Fibonacci and
// ➁ When all digits of number is Fibonacci
fmt.Print("\n Given ", n, " is full fibonacci number ")
} else {
fmt.Print("\n Given ", n, " is not fibonacci number ")
}
}
func main() {

// Test
isFullFibonacciNo(51)
isFullFibonacciNo(233)
isFullFibonacciNo(21)
isFullFibonacciNo(14)
}``````

Output

`````` Given 51 is not fibonacci number
Given 233 is full fibonacci number
Given 21 is full fibonacci number
Given 14 is not fibonacci number``````
``````<?php
// Php Program
// Determine that if given number is full Fibonacci Number
class FibonacciNumber
{
public	function isFibonacciNo(\$n)
{
//  5n²+4
\$a = 5 * \$n * \$n + 4;
//  5n²-4
\$b = 5 * \$n * \$n - 4;
\$aSqrt = (int) sqrt(\$a);
\$bSqrt = (int) sqrt(\$b);
if ((\$aSqrt * \$aSqrt) == \$a || (\$bSqrt * \$bSqrt) == \$b)
{
// When aSqrt or bSqrt is perfect square
return true;
}
return false;
}
public	function isFibonacciDigit(\$num)
{
\$n = \$num;
while (\$n > 0)
{
if (\$n % 10 == 4 && \$n % 10 == 6 &&
\$n % 10 == 7 && \$n % 10 == 9)
{
// When digit is not [1 2 3 5 8]
// Is not fibonacci digit
return false;
}
// Remove last digit
\$n = (int)(\$n / 10);
}
return true;
}
public	function isFullFibonacciNo(\$n)
{
if (\$n > 0 && \$this->isFibonacciNo(\$n) && \$this->isFibonacciDigit(\$n))
{
// ➀ When number Fibonacci and
// ➁ When all digits of number is Fibonacci
echo("\n Given ".\$n.
" is full fibonacci number ");
}
else
{
echo("\n Given ".\$n.
" is not fibonacci number ");
}
}
}

function main()
{
// Test
}
main();``````

Output

`````` Given 51 is not fibonacci number
Given 233 is full fibonacci number
Given 21 is full fibonacci number
Given 14 is not fibonacci number``````
``````// Node JS Program
// Determine that if given number is full Fibonacci Number
class FibonacciNumber
{
isFibonacciNo(n)
{
//  5n²+4
var a = 5 * n * n + 4;
//  5n²-4
var b = 5 * n * n - 4;
var aSqrt = parseInt(Math.sqrt(a));
var bSqrt = parseInt(Math.sqrt(b));
if ((aSqrt * aSqrt) == a || (bSqrt * bSqrt) == b)
{
// When aSqrt or bSqrt is perfect square
return true;
}
return false;
}
isFibonacciDigit(num)
{
var n = num;
while (n > 0)
{
if (n % 10 == 4 && n % 10 == 6 &&
n % 10 == 7 && n % 10 == 9)
{
// When digit is not [1 2 3 5 8]
// Is not fibonacci digit
return false;
}
// Remove last digit
n = parseInt(n / 10);
}
return true;
}
isFullFibonacciNo(n)
{
if (n > 0 && this.isFibonacciNo(n) &&
this.isFibonacciDigit(n))
{
// ➀ When number Fibonacci and
// ➁ When all digits of number is Fibonacci
process.stdout.write("\n Given " +
n + " is full fibonacci number ");
}
else
{
process.stdout.write("\n Given " +
n + " is not fibonacci number ");
}
}
}

function main()
{
// Test
}
main();``````

Output

`````` Given 51 is not fibonacci number
Given 233 is full fibonacci number
Given 21 is full fibonacci number
Given 14 is not fibonacci number``````
``````import math
#  Python 3 Program
#  Determine that if given number is full Fibonacci Number
class FibonacciNumber :
def isFibonacciNo(self, n) :
#   5n²+4
a = 5 * n * n + 4
#   5n²-4
b = 5 * n * n - 4
aSqrt = int(math.sqrt(a))
bSqrt = int(math.sqrt(b))
if ((aSqrt * aSqrt) == a or(bSqrt * bSqrt) == b) :
#  When aSqrt or bSqrt is perfect square
return True

return False

def isFibonacciDigit(self, num) :
n = num
while (n > 0) :
if (n % 10 == 4 and n % 10 == 6 and
n % 10 == 7 and n % 10 == 9) :
#  When digit is not [1 2 3 5 8]
#  Is not fibonacci digit
return False

#  Remove last digit
n = int(n / 10)

return True

def isFullFibonacciNo(self, n) :
if (n > 0 and self.isFibonacciNo(n) and
self.isFibonacciDigit(n)) :
#  ➀ When number Fibonacci and
#  ➁ When all digits of number is Fibonacci
print("\n Given ", n ," is full fibonacci number ", end = "")
else :
print("\n Given ", n ," is not fibonacci number ", end = "")

def main() :
#  Test

if __name__ == "__main__": main()``````

Output

`````` Given  51  is not fibonacci number
Given  233  is full fibonacci number
Given  21  is full fibonacci number
Given  14  is not fibonacci number``````
``````#  Ruby Program
#  Determine that if given number is full Fibonacci Number
class FibonacciNumber
def isFibonacciNo(n)
#   5n²+4
a = 5 * n * n + 4
#   5n²-4
b = 5 * n * n - 4
aSqrt = Math.sqrt(a).to_i
bSqrt = Math.sqrt(b).to_i
if ((aSqrt * aSqrt) == a ||
(bSqrt * bSqrt) == b)
#  When aSqrt or bSqrt is perfect square
return true
end

return false
end

def isFibonacciDigit(num)
n = num
while (n > 0)
if (n % 10 == 4 && n % 10 == 6 &&
n % 10 == 7 && n % 10 == 9)
#  When digit is not [1 2 3 5 8]
#  Is not fibonacci digit
return false
end

#  Remove last digit
n = n / 10
end

return true
end

def isFullFibonacciNo(n)
if (n > 0 && self.isFibonacciNo(n) &&
self.isFibonacciDigit(n))
#  ➀ When number Fibonacci and
#  ➁ When all digits of number is Fibonacci
print("\n Given ", n ," is full fibonacci number ")
else

print("\n Given ", n ," is not fibonacci number ")
end

end

end

def main()
#  Test
end

main()``````

Output

`````` Given 51 is not fibonacci number
Given 233 is full fibonacci number
Given 21 is full fibonacci number
Given 14 is not fibonacci number ``````
``````// Scala Program
// Determine that if given number is full Fibonacci Number
class FibonacciNumber()
{
def isFibonacciNo(n: Int): Boolean = {
//  5n²+4
var a: Int = 5 * n * n + 4;
//  5n²-4
var b: Int = 5 * n * n - 4;
var aSqrt: Int = scala.math.sqrt(a).toInt;
var bSqrt: Int = scala.math.sqrt(b).toInt;
if ((aSqrt * aSqrt) == a ||
(bSqrt * bSqrt) == b)
{
// When aSqrt or bSqrt is perfect square
return true;
}
return false;
}
def isFibonacciDigit(num: Int): Boolean = {
var n: Int = num;
while (n > 0)
{
if (n % 10 == 4 && n % 10 == 6 &&
n % 10 == 7 && n % 10 == 9)
{
// When digit is not [1 2 3 5 8]
// Is not fibonacci digit
return false;
}
// Remove last digit
n = n / 10;
}
return true;
}
def isFullFibonacciNo(n: Int): Unit = {
if (n > 0 && isFibonacciNo(n) && isFibonacciDigit(n))
{
// ➀ When number Fibonacci and
// ➁ When all digits of number is Fibonacci
print("\n Given " + n + " is full fibonacci number ");
}
else
{
print("\n Given " + n + " is not fibonacci number ");
}
}
}
object Main
{
def main(args: Array[String]): Unit = {
var task: FibonacciNumber = new FibonacciNumber();
// Test
}
}``````

Output

`````` Given 51 is not fibonacci number
Given 233 is full fibonacci number
Given 21 is full fibonacci number
Given 14 is not fibonacci number``````
``````import Foundation;
// Swift 4 Program
// Determine that if given number is full Fibonacci Number
class FibonacciNumber
{
func isFibonacciNo(_ n: Int) -> Bool
{
//  5n²+4
let a: Int = 5 * n * n + 4;
//  5n²-4
let b: Int = 5 * n * n - 4;
let aSqrt: Int = Int((Double(a)).squareRoot());
let bSqrt: Int = Int((Double(b)).squareRoot());
if ((aSqrt * aSqrt) == a ||
(bSqrt * bSqrt) == b)
{
// When aSqrt or bSqrt is perfect square
return true;
}
return false;
}
func isFibonacciDigit(_ num: Int) -> Bool
{
var n: Int = num;
while (n > 0)
{
if (n % 10 == 4 && n % 10 == 6 &&
n % 10 == 7 && n % 10 == 9)
{
// When digit is not [1 2 3 5 8]
// Is not fibonacci digit
return false;
}
// Remove last digit
n = n / 10;
}
return true;
}
func isFullFibonacciNo(_ n: Int)
{
if (n > 0 && self.isFibonacciNo(n) &&
self.isFibonacciDigit(n))
{
// ➀ When number Fibonacci and
// ➁ When all digits of number is Fibonacci
print("\n Given ", n ,
" is full fibonacci number ", terminator: "");
}
else
{
print("\n Given ", n ,
" is not fibonacci number ", terminator: "");
}
}
}
func main()
{
// Test
}
main();``````

Output

`````` Given  51  is not fibonacci number
Given  233  is full fibonacci number
Given  21  is full fibonacci number
Given  14  is not fibonacci number``````
``````// Kotlin Program
// Determine that if given number is full Fibonacci Number
class FibonacciNumber
{
fun isFibonacciNo(n: Int): Boolean
{
//  5n²+4
val a: Int = 5 * n * n + 4;
//  5n²-4
val b: Int = 5 * n * n - 4;
val aSqrt: Int = Math.sqrt(a.toDouble()).toInt();
val bSqrt: Int = Math.sqrt(b.toDouble()).toInt();
if ((aSqrt * aSqrt) == a || (bSqrt * bSqrt) == b)
{
// When aSqrt or bSqrt is perfect square
return true;
}
return false;
}
fun isFibonacciDigit(num: Int): Boolean
{
var n: Int = num;
while (n > 0)
{
if (n % 10 == 4 && n % 10 == 6 &&
n % 10 == 7 && n % 10 == 9)
{
// When digit is not [1 2 3 5 8]
// Is not fibonacci digit
return false;
}
// Remove last digit
n = n / 10;
}
return true;
}
fun isFullFibonacciNo(n: Int): Unit
{
if (n > 0 && this.isFibonacciNo(n) &&
this.isFibonacciDigit(n))
{
// ➀ When number Fibonacci and
// ➁ When all digits of number is Fibonacci
print("\n Given " + n + " is full fibonacci number ");
}
else
{
print("\n Given " + n + " is not fibonacci number ");
}
}
}
fun main(args: Array < String > ): Unit
{
// Test
}``````

Output

`````` Given 51 is not fibonacci number
Given 233 is full fibonacci number
Given 21 is full fibonacci number
Given 14 is not fibonacci number``````

Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

Categories
Relative Post