Skip to main content

Reverse fibonacci series

Here given code implementation process.

//C Program
//Reverse fibonacci sequence
#include <stdio.h>

void view_series(int first,int second,int n)
{

  if(n > 0)
  {
    view_series(second,first + second,n-1);

    printf("  %d",first );
  } 
}


void fibonacci(int n)
{
  //Set the initial value of variable
  //This is two initial value
  int first = 0;
  
  int second = 1;

  view_series(first,second,n);
  
}
int main()
{
 
  int n = 20;
  
  fibonacci(n);

  return 0;
}

Output

  4181  2584  1597  987  610  377  233  144  89  55  34  21  13  8  5  3  2  1  1  0
/*
  C++ Program
  Reverse fibonacci sequence
*/
#include <iostream>

using namespace std;
class MyNumber {
public:
  void view_series(int first, int second, int n) {
    if (n > 0) {
      this->view_series(second, first + second, n - 1);
      cout << "  " << first;
    }
  }
  void fibonacci(int n) {
    int first = 0;
    int second = 1;
    this->view_series(first, second, n);
  }
};

int main() {
  MyNumber obj ;
  int n = 20;
  obj.fibonacci(n);
}

Output

  4181  2584  1597  987  610  377  233  144  89  55  34  21  13  8  5  3  2  1  1  0
/*
  Java Program
  Reverse fibonacci sequence
*/

public class MyNumber {

  public void view_series(int first,int second,int n)
  {

    if(n > 0)
    {
      view_series(second,first + second,n-1);

      System.out.print("  "+first );
    } 
  }

  public void fibonacci(int n)
  {
    //Set the initial value of variable
    //This is two initial value
    int first = 0;
    
    int second = 1;

    view_series(first,second,n);
    
  }
  public static void main(String[] args) {
    
    MyNumber obj = new MyNumber();

    int n = 20;
  
    obj.fibonacci(n);
  }


}

Output

  4181  2584  1597  987  610  377  233  144  89  55  34  21  13  8  5  3  2  1  1  0
/*
  C# Program
  Reverse fibonacci sequence
*/
using System;
public class MyNumber {

	public void view_series(int first,int second,int n)
	{

		if(n > 0)
		{
			view_series(second,first + second,n-1);

			Console.Write("  "+first );
		} 
	}

	public void fibonacci(int n)
	{
		//Set the initial value of variable
		//This is two initial value
		int first = 0;

		int second = 1;

		view_series(first,second,n);

	}
	public static void Main(String[] args) {

		MyNumber obj = new MyNumber();

		int n = 20;

		obj.fibonacci(n);
	}


}

Output

  4181  2584  1597  987  610  377  233  144  89  55  34  21  13  8  5  3  2  1  1  0
# Ruby Program
# Reverse fibonacci sequence

class MyNumber :
  def view_series(self, first, second, n) :
    if (n > 0) :
      self.view_series(second, first + second, n - 1);
      print(first,end="  ");
    
  
  def fibonacci(self, n) :
    first = 0;
    second = 1;
    self.view_series(first, second, n);
  


def main() :
  obj = MyNumber();
  n = 20;
  obj.fibonacci(n);
  

if __name__ == "__main__":
  main()

Output

  4181  2584  1597  987  610  377  233  144  89  55  34  21  13  8  5  3  2  1  1  0
# Ruby Program
# Reverse fibonacci sequence

class MyNumber 
	def view_series(first, second, n) 
		if (n > 0) 
			self.view_series(second, first + second, n - 1)
			print("  ", first)
		end
	end
	def fibonacci(n) 
		first = 0
		second = 1
		self.view_series(first, second, n)
	end
end
def main() 
	obj = MyNumber.new()
	n = 20
	obj.fibonacci(n)
end
main()

Output

  4181  2584  1597  987  610  377  233  144  89  55  34  21  13  8  5  3  2  1  1  0
<?php
/*
  Php Program
  Reverse fibonacci sequence
*/

class MyNumber {
  public  function view_series($first, $second, $n) {
    if ($n > 0) {
      $this->view_series($second, $first + $second, $n - 1);
      echo "  ". $first;
    }
  }
  public  function fibonacci($n) {
    $first = 0;
    $second = 1;
    $this->view_series($first, $second, $n);
  }

}

function main() {
  $obj = new MyNumber();
  $n = 20;
  $obj->fibonacci($n);
}
main();

Output

  4181  2584  1597  987  610  377  233  144  89  55  34  21  13  8  5  3  2  1  1  0
/*
  Node JS Program
  Reverse fibonacci sequence
*/

class MyNumber {
	view_series(first, second, n) {
		if (n > 0) {
			this.view_series(second, first + second, n - 1);
			process.stdout.write("  " + first);
		}
	}
	fibonacci(n) {
		var first = 0;
		var second = 1;
		this.view_series(first, second, n);
	}
}

function main() {
	var obj = new MyNumber();
	var n = 20;
	obj.fibonacci(n);
}
main();

Output

  4181  2584  1597  987  610  377  233  144  89  55  34  21  13  8  5  3  2  1  1  0
/*
  Swift 4 Program
  Reverse fibonacci sequence
*/
class MyNumber {

  func view_series(_ first: Int, _ second: Int, _ n: Int) {
    if (n > 0) {
      self.view_series(second, first + second, n - 1);
      print(first,terminator:"  ");
    }
  }
  func fibonacci(_ n: Int) {
    let first: Int = 0;
    let second: Int = 1;
    self.view_series(first, second, n);
  }
}
func main() {
  let obj: MyNumber = MyNumber();
  let n: Int = 20;
  obj.fibonacci(n);
}
main();

Output

  4181  2584  1597  987  610  377  233  144  89  55  34  21  13  8  5  3  2  1  1  0




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.

New Comment