Pell Number

Here given code implementation process.

/*
  C Program 
+ Print Pell Number Series
*/
#include<stdio.h>

//Display pell number in given size
void pell_numbers(int size)
{

  //Setup initial value
  int a = 1;
  int b = 0;
  int c = 0;

  for (int i = 0; i < size; ++i)
  {
    //Get pell number
    c = 2 * b + a;
    a = b;
    b = c;
    printf("%d  ",c );
  }
 
}
int main(){

  //Test Case
  pell_numbers(10);
 
  return 0;
}

Output

1  2  5  12  29  70  169  408  985  2378
/*
 C++ Program
 Print Pell Number Series
*/
#include<iostream>

using namespace std;

class MyNumber {
	public:

		//Display pell number in given size
		void pell_numbers(int size) {
			//Setup initial value
			int a = 1;
			int b = 0;
			int c = 0;
			for (int i = 0; i < size; ++i) {
				//Get pell number
				c = 2 *b + a;
				a = b;
				b = c;
				cout << " " << c;
			}
		}
};
int main() {
	MyNumber obj;
	obj.pell_numbers(10);
	return 0;
}

Output

 1 2 5 12 29 70 169 408 985 2378
/*
  Java Program
  Print Pell Number Series
*/
public class MyNumber {
 

  //Display pell number in given size
  public void pell_numbers(int size)
  {

    //Setup initial value
    int a = 1;
    int b = 0;
    int c = 0;

    for (int i = 0; i < size; ++i)
    {
      //Get pell number
      c = 2 * b + a;
      a = b;
      b = c;
      System.out.print("  "+c );
    }
   
  }
 
  public static void main(String[] args) {

    MyNumber obj = new MyNumber();

    obj.pell_numbers(10);
  }
}

Output

 1 2 5 12 29 70 169 408 985 2378
/*
  C# Program
  Print Pell Number Series
*/
using System;
public class MyNumber {


	//Display pell number in given size
	public void pell_numbers(int size) {

		//Setup initial value
		int a = 1;
		int b = 0;
		int c = 0;

		for (int i = 0; i < size; ++i) {
			//Get pell number
			c = 2 * b + a;
			a = b;
			b = c;
			Console.Write("  " + c);
		}

	}

	public static void Main(String[] args) {

		MyNumber obj = new MyNumber();

		obj.pell_numbers(10);
	}
}

Output

  1  2  5  12  29  70  169  408  985  2378
<?php
/*
  Php Program
  Print Pell Number Series
*/
class MyNumber {
	//Display pell number in given size

	public 	function pell_numbers($size) {
		//Setup initial value
		$a = 1;
		$b = 0;
		$c = 0;
		for ($i = 0; $i < $size; ++$i) {
			//Get pell number
			$c = 2 *$b + $a;
			$a = $b;
			$b = $c;
			echo(" ". $c);
		}
	}
};

function main() {
	$obj = new MyNumber();
	$obj->pell_numbers(10);
}
main();

Output

 1 2 5 12 29 70 169 408 985 2378
/*
 Node Js Program
 Print Pell Number Series
*/
class MyNumber {
	//Display pell number in given size
	pell_numbers(size) {
		//Setup initial value
		var a = 1;
		var b = 0;
		var c = 0;
		for (var i = 0; i < size; ++i) {
			//Get pell number
			c = 2 *b + a;
			a = b;
			b = c;
			process.stdout.write(" " + c);
		}
	}
}

function main(args) {
	var obj = new MyNumber();
	obj.pell_numbers(10);
}
main();

Output

 1 2 5 12 29 70 169 408 985 2378
# Python 3 Program
# Print Pell Number Series
class MyNumber :
	# Display pell number in given size
	def pell_numbers(self, size) :
		# Setup initial value
		a = 1
		b = 0
		c = 0
		i = 0
		while (i < size) :
			# Get pell number
			c = 2 * b + a
			a = b
			b = c
			print(" ", c,end="")
			i += 1
		
	

def main() :
	obj = MyNumber()
	obj.pell_numbers(10)


if __name__ == "__main__":
	main()

Output

 1  2  5  12  29  70  169  408  985  2378
# Ruby Program 

# Print Pell Number Series
class MyNumber 
	# Display pell number in given size
	def pell_numbers(size) 
		# Setup initial value
		a = 1
		b = 0
		c = 0
		i = 0
		while (i < size) 
			# Get pell number
			c = 2 * b + a
			a = b
			b = c
			print(" ", c)
			i += 1
		end
	end
end
def main() 
	obj = MyNumber.new()
	obj.pell_numbers(10)
end
main()

Output

 1 2 5 12 29 70 169 408 985 2378
/*
 Scala Program
  Print Pell Number Series
*/
class MyNumber {
	//Display pell number in given size
	def pell_numbers(size: Int): Unit = {
		//Setup initial value
		var a: Int = 1;
		var b: Int = 0;
		var c: Int = 0;
		var i: Int = 0;
		while (i < size) {
			//Get pell number
			c = 2 * b + a;
			a = b;
			b = c;
			print(" " + c);
			i += 1;
		}
	}
}
object Main {
	def main(args: Array[String]): Unit = {
		var obj: MyNumber = new MyNumber();
  		obj.pell_numbers(10);
	}
}

Output

 1 2 5 12 29 70 169 408 985 2378
/*
  Swift 4 Program
  Print Pell Number Series
*/
class MyNumber {
	//Display pell number in given size
	func pell_numbers(_ size: Int) {
		//Setup initial value
		var a: Int = 1;
		var b: Int = 0;
		var c: Int = 0;
		var i: Int = 0;
		while (i < size) {
			//Get pell number
			c = 2 * b + a;
			a = b;
			b = c;
			print(" ", c,terminator:"");
			i += 1;
		}
	}
}
func main() {
	let obj: MyNumber = MyNumber();
	obj.pell_numbers(10);
}
main();

Output

  1  2  5  12  29  70  169  408  985  2378


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