Find Nth even fibonacci number

Here given code implementation process.

// C program
// Find Nth even fibonacci number
#include <stdio.h>

//Find n-th Even Number in a fibonacci series
long long int even_fib_element(int n)
{
	if (n < 1)
	{
		//When n is less than 1
		return n;
	}
	else if (n == 1)
	{
		//When n is equal to 1
		return 2;
	}
	// Recursively detect nth even element
	return ((4 * even_fib_element(n - 1)) + even_fib_element(n - 2));
}
//This function are handling the request of finding nth Even Number 
void fibonacci_node(int n_th)
{
	if (n_th <= 0)
	{
		return;
	}
	long long int result = even_fib_element(n_th);
	//Display calculated result
	printf("\n %d-th Even fibonacci element is : %lld ", n_th, result);
}
int main()
{
	//Test case
	fibonacci_node(2);
	fibonacci_node(9);
	fibonacci_node(6);
	fibonacci_node(4);
	fibonacci_node(7);
	return 0;
}

Output

 2-th Even fibonacci element is : 8
 9-th Even fibonacci element is : 196418
 6-th Even fibonacci element is : 2584
 4-th Even fibonacci element is : 144
 7-th Even fibonacci element is : 10946
// Java program 
// Find Nth Odd fibonacci number
class FibonacciNo
{
	//Find n-th Even Number in a fibonacci series
	public long even_fib_element(int n)
	{
		if (n < 1)
		{
			//When n is less than 1
			return n;
		}
		else if (n == 1)
		{
			//When n is equal to 1
			return 2;
		}
		// Recursively detect nth even element
		return ((4 * even_fib_element(n - 1)) + even_fib_element(n - 2));
	}
	//This function are handling the request of finding nth Even Number 
	public void fibonacci_node(int n_th)
	{
		if (n_th <= 0)
		{
			return;
		}
		long result = even_fib_element(n_th);
		//Display calculated result
		System.out.print("\n " + n_th + "-th Even fibonacci element is : " + result + " ");
	}
	public static void main(String[] args)
	{
		FibonacciNo obj = new FibonacciNo();
		//Test case
		obj.fibonacci_node(2);
		obj.fibonacci_node(9);
		obj.fibonacci_node(6);
		obj.fibonacci_node(4);
		obj.fibonacci_node(7);
	}
}

Output

 2-th Even fibonacci element is : 8
 9-th Even fibonacci element is : 196418
 6-th Even fibonacci element is : 2584
 4-th Even fibonacci element is : 144
 7-th Even fibonacci element is : 10946
//Include header file
#include <iostream>

using namespace std;
// C++ program 
// Find Nth Odd fibonacci number
class FibonacciNo
{
	public:
		//Find n-th Even Number in a fibonacci series
		long even_fib_element(int n)
		{
			if (n < 1)
			{
				//When n is less than 1
				return n;
			}
			else if (n == 1)
			{
				//When n is equal to 1
				return 2;
			}
			// Recursively detect nth even element
			return ((4 *this->even_fib_element(n - 1)) + this->even_fib_element(n - 2));
		}
	//This function are handling the request of finding nth Even Number 
	void fibonacci_node(int n_th)
	{
		if (n_th <= 0)
		{
			return;
		}
		long result = this->even_fib_element(n_th);
		//Display calculated result
		cout << "\n " << n_th << "-th Even fibonacci element is : " << result << " ";
	}
};
int main()
{
	FibonacciNo obj = FibonacciNo();
	//Test case
	obj.fibonacci_node(2);
	obj.fibonacci_node(9);
	obj.fibonacci_node(6);
	obj.fibonacci_node(4);
	obj.fibonacci_node(7);
	return 0;
}

Output

 2-th Even fibonacci element is : 8
 9-th Even fibonacci element is : 196418
 6-th Even fibonacci element is : 2584
 4-th Even fibonacci element is : 144
 7-th Even fibonacci element is : 10946
//Include namespace system
using System;

// C# program 
// Find Nth Odd fibonacci number

class FibonacciNo
{
	//Find n-th Even Number in a fibonacci series
	public long even_fib_element(int n)
	{
		if (n < 1)
		{
			//When n is less than 1
			return n;
		}
		else if (n == 1)
		{
			//When n is equal to 1
			return 2;
		}
		// Recursively detect nth even element
		return ((4 * even_fib_element(n - 1)) + even_fib_element(n - 2));
	}
	//This function are handling the request of finding nth Even Number 
	public void fibonacci_node(int n_th)
	{
		if (n_th <= 0)
		{
			return;
		}
		long result = even_fib_element(n_th);
		//Display calculated result
		Console.Write("\n " + n_th + "-th Even fibonacci element is : " + result + " ");
	}
	public static void Main(String[] args)
	{
		FibonacciNo obj = new FibonacciNo();
		//Test case
		obj.fibonacci_node(2);
		obj.fibonacci_node(9);
		obj.fibonacci_node(6);
		obj.fibonacci_node(4);
		obj.fibonacci_node(7);
	}
}

Output

 2-th Even fibonacci element is : 8
 9-th Even fibonacci element is : 196418
 6-th Even fibonacci element is : 2584
 4-th Even fibonacci element is : 144
 7-th Even fibonacci element is : 10946
<?php
// Php program 
// Find Nth Odd fibonacci number

class FibonacciNo
{
	//Find n-th Even Number in a fibonacci series
	public	function even_fib_element($n)
	{
		if ($n < 1)
		{
			//When n is less than 1
			return $n;
		}
		else if ($n == 1)
		{
			//When n is equal to 1
			return 2;
		}
		// Recursively detect nth even element
		return ((4 * $this->even_fib_element($n - 1)) + $this->even_fib_element($n - 2));
	}
	//This function are handling the request of finding nth Even Number 
	public	function fibonacci_node($n_th)
	{
		if ($n_th <= 0)
		{
			return;
		}
		$result = $this->even_fib_element($n_th);
		//Display calculated result
		echo "\n ". $n_th ."-th Even fibonacci element is : ". $result ." ";
	}
}

function main()
{
	$obj = new FibonacciNo();
	//Test case
	$obj->fibonacci_node(2);
	$obj->fibonacci_node(9);
	$obj->fibonacci_node(6);
	$obj->fibonacci_node(4);
	$obj->fibonacci_node(7);
}
main();

Output

 2-th Even fibonacci element is : 8
 9-th Even fibonacci element is : 196418
 6-th Even fibonacci element is : 2584
 4-th Even fibonacci element is : 144
 7-th Even fibonacci element is : 10946
// Node Js program 
// Find Nth Odd fibonacci number
class FibonacciNo
{
	//Find n-th Even Number in a fibonacci series
	even_fib_element(n)
	{
		if (n < 1)
		{
			//When n is less than 1
			return n;
		}
		else if (n == 1)
		{
			//When n is equal to 1
			return 2;
		}
		// Recursively detect nth even element
		return ((4 * this.even_fib_element(n - 1)) + this.even_fib_element(n - 2));
	}
	//This function are handling the request of finding nth Even Number 
	fibonacci_node(n_th)
	{
		if (n_th <= 0)
		{
			return;
		}
		var result = this.even_fib_element(n_th);
		//Display calculated result
		process.stdout.write("\n " + n_th + "-th Even fibonacci element is : " + result + " ");
	}
}

function main()
{
	var obj = new FibonacciNo();
	//Test case
	obj.fibonacci_node(2);
	obj.fibonacci_node(9);
	obj.fibonacci_node(6);
	obj.fibonacci_node(4);
	obj.fibonacci_node(7);
}
main();

Output

 2-th Even fibonacci element is : 8
 9-th Even fibonacci element is : 196418
 6-th Even fibonacci element is : 2584
 4-th Even fibonacci element is : 144
 7-th Even fibonacci element is : 10946
#  Python 3 program 
#  Find Nth Odd fibonacci number
class FibonacciNo :
	# Find n-th Even Number in a fibonacci series
	def even_fib_element(self, n) :
		if (n < 1) :
			# When n is less than 1
			return n
		
		elif(n == 1) :
			# When n is equal to 1
			return 2
		
		#  Recursively detect nth even element
		return ((4 * self.even_fib_element(n - 1)) + self.even_fib_element(n - 2))
	
	# This function are handling the request of finding nth Even Number 
	def fibonacci_node(self, n_th) :
		if (n_th <= 0) :
			return
		
		result = self.even_fib_element(n_th)
		# Display calculated result
		print("\n ", n_th ,"-th Even fibonacci element is : ", result ," ", end = "")
	

def main() :
	obj = FibonacciNo()
	# Test case
	obj.fibonacci_node(2)
	obj.fibonacci_node(9)
	obj.fibonacci_node(6)
	obj.fibonacci_node(4)
	obj.fibonacci_node(7)

if __name__ == "__main__": main()

Output

  2 -th Even fibonacci element is :  8
  9 -th Even fibonacci element is :  196418
  6 -th Even fibonacci element is :  2584
  4 -th Even fibonacci element is :  144
  7 -th Even fibonacci element is :  10946
#  Ruby program 
#  Find Nth Odd fibonacci number
class FibonacciNo 
	# Find n-th Even Number in a fibonacci series
	def even_fib_element(n) 
		if (n < 1) 
			# When n is less than 1
			return n
		elsif(n == 1) 
			# When n is equal to 1
			return 2
		end

		#  Recursively detect nth even element
		return ((4 * self.even_fib_element(n - 1)) + self.even_fib_element(n - 2))
	end

	# This function are handling the request of finding nth Even Number 
	def fibonacci_node(n_th) 
		if (n_th <= 0) 
			return
		end

		result = self.even_fib_element(n_th)
		# Display calculated result
		print("\n ", n_th ,"-th Even fibonacci element is : ", result ," ")
	end

end

def main() 
	obj = FibonacciNo.new()
	# Test case
	obj.fibonacci_node(2)
	obj.fibonacci_node(9)
	obj.fibonacci_node(6)
	obj.fibonacci_node(4)
	obj.fibonacci_node(7)
end

main()

Output

 2-th Even fibonacci element is : 8 
 9-th Even fibonacci element is : 196418 
 6-th Even fibonacci element is : 2584 
 4-th Even fibonacci element is : 144 
 7-th Even fibonacci element is : 10946 
// Scala program 
// Find Nth Odd fibonacci number
class FibonacciNo
{
	//Find n-th Even Number in a fibonacci series
	def even_fib_element(n: Int): Long = {
		if (n < 1)
		{
			//When n is less than 1
			return n;
		}
		else if (n == 1)
		{
			//When n is equal to 1
			return 2;
		}
		// Recursively detect nth even element
		return ((4 * even_fib_element(n - 1)) + even_fib_element(n - 2));
	}
	//This function are handling the request of finding nth Even Number 
	def fibonacci_node(n_th: Int): Unit = {
		if (n_th <= 0)
		{
			return;
		}
		var result: Long = even_fib_element(n_th);
		//Display calculated result
		print("\n " + n_th + "-th Even fibonacci element is : " + result + " ");
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var obj: FibonacciNo = new FibonacciNo();
		//Test case
		obj.fibonacci_node(2);
		obj.fibonacci_node(9);
		obj.fibonacci_node(6);
		obj.fibonacci_node(4);
		obj.fibonacci_node(7);
	}
}

Output

 2-th Even fibonacci element is : 8
 9-th Even fibonacci element is : 196418
 6-th Even fibonacci element is : 2584
 4-th Even fibonacci element is : 144
 7-th Even fibonacci element is : 10946
// Swift 4 program 
// Find Nth Odd fibonacci number
class FibonacciNo
{
	//Find n-th Even Number in a fibonacci series
	func even_fib_element(_ n: Int) -> Int
	{
		if (n < 1)
		{
			//When n is less than 1
			return n;
		}
		else if (n == 1)
		{
			//When n is equal to 1
			return 2;
		}
		// Recursively detect nth even element
		return ((4 * self.even_fib_element(n - 1)) + self.even_fib_element(n - 2));
	}
	//This function are handling the request of finding nth Even Number 
	func fibonacci_node(_ n_th: Int)
	{
		if (n_th <= 0)
		{
			return;
		}
		let result: Int = self.even_fib_element(n_th);
		//Display calculated result
		print("\n ", n_th ,"-th Even fibonacci element is : ", result ," ", terminator: "");
	}
}
func main()
{
	let obj: FibonacciNo = FibonacciNo();
	//Test case
	obj.fibonacci_node(2);
	obj.fibonacci_node(9);
	obj.fibonacci_node(6);
	obj.fibonacci_node(4);
	obj.fibonacci_node(7);
}
main();

Output

  2 -th Even fibonacci element is :  8
  9 -th Even fibonacci element is :  196418
  6 -th Even fibonacci element is :  2584
  4 -th Even fibonacci element is :  144
  7 -th Even fibonacci element is :  10946


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.

New Comment







© 2021, kalkicode.com, All rights reserved