Fibonacci series in reverse order

Here given code implementation process.

/*
    C program for
    Fibonacci series in reverse order
*/
#include <stdio.h>

void fibonacciNumber(int a, int b, int n)
{
    if(n <= 0)
    {
        return;
    }
    // Find fibonacci series using recursion
    fibonacciNumber(b, a+b, n-1);

    // Display fibonacci number
    printf(" %d",a);
}
int main(int argc, char const *argv[])
{

    // Display size 
    int n = 10;
    printf("\n Reversal fibonacci series of size %d is \n",n);
    // n = 10
    fibonacciNumber(0,1,n);

    n = 15;
    printf("\n Reversal fibonacci series of size %d is \n",n);
    // n = 15
    fibonacciNumber(0,1,n);
    return 0;
}

Output

 Reversal fibonacci series of size 10 is
 34 21 13 8 5 3 2 1 1 0
 Reversal fibonacci series of size 15 is
 377 233 144 89 55 34 21 13 8 5 3 2 1 1 0
/*
    Java program for
    Fibonacci series in reverse order
*/
public class FibonacciSeries
{
	public void fibonacciNumber(int a, int b, int n)
	{
		if (n <= 0)
		{
			return;
		}
		// Find fibonacci series using recursion
		fibonacciNumber(b, a + b, n - 1);
		// Display fibonacci number
		System.out.print(" " + a);
	}
	public static void main(String[] args)
	{
		FibonacciSeries task = new FibonacciSeries();
		// Display size 
		int n = 10;
		System.out.print("\n Reversal fibonacci series of size " + n + " is \n");
		// n = 10
		task.fibonacciNumber(0, 1, n);
		n = 15;
		System.out.print("\n Reversal fibonacci series of size " + n + " is \n");
		// n = 15
		task.fibonacciNumber(0, 1, n);
	}
}

Output

 Reversal fibonacci series of size 10 is
 34 21 13 8 5 3 2 1 1 0
 Reversal fibonacci series of size 15 is
 377 233 144 89 55 34 21 13 8 5 3 2 1 1 0
// Include header file
#include <iostream>
using namespace std;
/*
    C++ program for
    Fibonacci series in reverse order
*/
class FibonacciSeries
{
	public: void fibonacciNumber(int a, int b, int n)
	{
		if (n <= 0)
		{
			return;
		}
		// Find fibonacci series using recursion
		this->fibonacciNumber(b, a + b, n - 1);
		// Display fibonacci number
		cout << " " << a;
	}
};
int main()
{
	FibonacciSeries *task = new FibonacciSeries();
	// Display size 
	int n = 10;
	cout << "\n Reversal fibonacci series of size " << n << " is \n";
	// n = 10
	task->fibonacciNumber(0, 1, n);
	n = 15;
	cout << "\n Reversal fibonacci series of size " << n << " is \n";
	// n = 15
	task->fibonacciNumber(0, 1, n);
	return 0;
}

Output

 Reversal fibonacci series of size 10 is
 34 21 13 8 5 3 2 1 1 0
 Reversal fibonacci series of size 15 is
 377 233 144 89 55 34 21 13 8 5 3 2 1 1 0
// Include namespace system
using System;
/*
    Csharp program for
    Fibonacci series in reverse order
*/
public class FibonacciSeries
{
	public void fibonacciNumber(int a, int b, int n)
	{
		if (n <= 0)
		{
			return;
		}
		// Find fibonacci series using recursion
		this.fibonacciNumber(b, a + b, n - 1);
		// Display fibonacci number
		Console.Write(" " + a);
	}
	public static void Main(String[] args)
	{
		FibonacciSeries task = new FibonacciSeries();
		// Display size 
		int n = 10;
		Console.Write("\n Reversal fibonacci series of size " + n + " is \n");
		// n = 10
		task.fibonacciNumber(0, 1, n);
		n = 15;
		Console.Write("\n Reversal fibonacci series of size " + n + " is \n");
		// n = 15
		task.fibonacciNumber(0, 1, n);
	}
}

Output

 Reversal fibonacci series of size 10 is
 34 21 13 8 5 3 2 1 1 0
 Reversal fibonacci series of size 15 is
 377 233 144 89 55 34 21 13 8 5 3 2 1 1 0
package main
import "fmt"
/*
    Go program for
    Fibonacci series in reverse order
*/
func fibonacciNumber(a, b, n int) {
	if n <= 0 {
		return
	}
	// Find fibonacci series using recursion
	fibonacciNumber(b, a + b, n - 1)
	// Display fibonacci number
	fmt.Print(" ", a)
}
func main() {
	
	// Display size 
	var n int = 10
	fmt.Print("\n Reversal fibonacci series of size ", n, " is \n")
	// n = 10
	fibonacciNumber(0, 1, n)
	n = 15
	fmt.Print("\n Reversal fibonacci series of size ", n, " is \n")
	// n = 15
	fibonacciNumber(0, 1, n)
}

Output

 Reversal fibonacci series of size 10 is 
 34 21 13 8 5 3 2 1 1 0
 Reversal fibonacci series of size 15 is 
 377 233 144 89 55 34 21 13 8 5 3 2 1 1 0
<?php
/*
    Php program for
    Fibonacci series in reverse order
*/
class FibonacciSeries
{
	public	function fibonacciNumber($a, $b, $n)
	{
		if ($n <= 0)
		{
			return;
		}
		// Find fibonacci series using recursion
		$this->fibonacciNumber($b, $a + $b, $n - 1);
		// Display fibonacci number
		echo(" ".$a);
	}
}

function main()
{
	$task = new FibonacciSeries();
	// Display size 
	$n = 10;
	echo("\n Reversal fibonacci series of size ".$n." is \n");
	// n = 10
	$task->fibonacciNumber(0, 1, $n);
	$n = 15;
	echo("\n Reversal fibonacci series of size ".$n." is \n");
	// n = 15
	$task->fibonacciNumber(0, 1, $n);
}
main();

Output

 Reversal fibonacci series of size 10 is
 34 21 13 8 5 3 2 1 1 0
 Reversal fibonacci series of size 15 is
 377 233 144 89 55 34 21 13 8 5 3 2 1 1 0
/*
    Node JS program for
    Fibonacci series in reverse order
*/
class FibonacciSeries
{
	fibonacciNumber(a, b, n)
	{
		if (n <= 0)
		{
			return;
		}
		// Find fibonacci series using recursion
		this.fibonacciNumber(b, a + b, n - 1);
		// Display fibonacci number
		process.stdout.write(" " + a);
	}
}

function main()
{
	var task = new FibonacciSeries();
	// Display size 
	var n = 10;
	process.stdout.write("\n Reversal fibonacci series of size " + n + " is \n");
	// n = 10
	task.fibonacciNumber(0, 1, n);
	n = 15;
	process.stdout.write("\n Reversal fibonacci series of size " + n + " is \n");
	// n = 15
	task.fibonacciNumber(0, 1, n);
}
main();

Output

 Reversal fibonacci series of size 10 is
 34 21 13 8 5 3 2 1 1 0
 Reversal fibonacci series of size 15 is
 377 233 144 89 55 34 21 13 8 5 3 2 1 1 0
#    Python 3 program for
#    Fibonacci series in reverse order
class FibonacciSeries :
	def fibonacciNumber(self, a, b, n) :
		if (n <= 0) :
			return
		
		#  Find fibonacci series using recursion
		self.fibonacciNumber(b, a + b, n - 1)
		#  Display fibonacci number
		print(" ", a, end = "")
	

def main() :
	task = FibonacciSeries()
	#  Display size 
	n = 10
	print("\n Reversal fibonacci series of size ", n ," is ")
	#  n = 10
	task.fibonacciNumber(0, 1, n)
	n = 15
	print("\n Reversal fibonacci series of size ", n ," is ")
	#  n = 15
	task.fibonacciNumber(0, 1, n)

if __name__ == "__main__": main()

Output

 Reversal fibonacci series of size  10  is
  34  21  13  8  5  3  2  1  1  0
 Reversal fibonacci series of size  15  is
  377  233  144  89  55  34  21  13  8  5  3  2  1  1  0
#    Ruby program for
#    Fibonacci series in reverse order
class FibonacciSeries 
	def fibonacciNumber(a, b, n) 
		if (n <= 0) 
			return
		end

		#  Find fibonacci series using recursion
		self.fibonacciNumber(b, a + b, n - 1)
		#  Display fibonacci number
		print(" ", a)
	end

end

def main() 
	task = FibonacciSeries.new()
	#  Display size 
	n = 10
	print("\n Reversal fibonacci series of size ", n ," is \n")
	#  n = 10
	task.fibonacciNumber(0, 1, n)
	n = 15
	print("\n Reversal fibonacci series of size ", n ," is \n")
	#  n = 15
	task.fibonacciNumber(0, 1, n)
end

main()

Output

 Reversal fibonacci series of size 10 is 
 34 21 13 8 5 3 2 1 1 0
 Reversal fibonacci series of size 15 is 
 377 233 144 89 55 34 21 13 8 5 3 2 1 1 0
/*
    Scala program for
    Fibonacci series in reverse order
*/
class FibonacciSeries()
{
	def fibonacciNumber(a: Int, b: Int, n: Int): Unit = {
		if (n <= 0)
		{
			return;
		}
		// Find fibonacci series using recursion
		fibonacciNumber(b, a + b, n - 1);
		// Display fibonacci number
		print(" " + a);
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: FibonacciSeries = new FibonacciSeries();
		// Display size 
		var n: Int = 10;
		print("\n Reversal fibonacci series of size " + n + " is \n");
		// n = 10
		task.fibonacciNumber(0, 1, n);
		n = 15;
		print("\n Reversal fibonacci series of size " + n + " is \n");
		// n = 15
		task.fibonacciNumber(0, 1, n);
	}
}

Output

 Reversal fibonacci series of size 10 is
 34 21 13 8 5 3 2 1 1 0
 Reversal fibonacci series of size 15 is
 377 233 144 89 55 34 21 13 8 5 3 2 1 1 0
/*
    Swift 4 program for
    Fibonacci series in reverse order
*/
class FibonacciSeries
{
	func fibonacciNumber(_ a: Int, _ b: Int, _ n: Int)
	{
		if (n <= 0)
		{
			return;
		}
		// Find fibonacci series using recursion
		self.fibonacciNumber(b, a + b, n - 1);
		// Display fibonacci number
		print(" ", a, terminator: "");
	}
}
func main()
{
	let task: FibonacciSeries = FibonacciSeries();
	// Display size 
	var n: Int = 10;
	print("\n Reversal fibonacci series of size ", n ," is ");
	// n = 10
	task.fibonacciNumber(0, 1, n);
	n = 15;
	print("\n Reversal fibonacci series of size ", n ," is ");
	// n = 15
	task.fibonacciNumber(0, 1, n);
}
main();

Output

 Reversal fibonacci series of size  10  is
  34  21  13  8  5  3  2  1  1  0
 Reversal fibonacci series of size  15  is
  377  233  144  89  55  34  21  13  8  5  3  2  1  1  0
/*
    Kotlin program for
    Fibonacci series in reverse order
*/
class FibonacciSeries
{
	fun fibonacciNumber(a: Int, b: Int, n: Int): Unit
	{
		if (n <= 0)
		{
			return;
		}
		// Find fibonacci series using recursion
		this.fibonacciNumber(b, a + b, n - 1);
		// Display fibonacci number
		print(" " + a);
	}
}
fun main(args: Array < String > ): Unit
{
	val task: FibonacciSeries = FibonacciSeries();
	// Display size 
	var n: Int = 10;
	print("\n Reversal fibonacci series of size " + n + " is \n");
	// n = 10
	task.fibonacciNumber(0, 1, n);
	n = 15;
	print("\n Reversal fibonacci series of size " + n + " is \n");
	// n = 15
	task.fibonacciNumber(0, 1, n);
}

Output

 Reversal fibonacci series of size 10 is
 34 21 13 8 5 3 2 1 1 0
 Reversal fibonacci series of size 15 is
 377 233 144 89 55 34 21 13 8 5 3 2 1 1 0


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