Preloader
PseInt
  • Estimated reading time: 1 Minute

How to print the first N numbers of the Fibonacci series in PseInt

magzin

In multiple practice exercises at school or university, at some point you will have to develop a program that prints the first N numbers of the famous Fibonacci series. p. ex: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34. This series is described in a short way, assuming that each number is obtained from the sum of the two previous numbers in the series .

This sequence was described by Fibonacci as the solution to a rabbit breeding problem: “A certain man has a pair of rabbits together in a closed place and he wants to know how many are created from this pair in a year when, according to his nature, each couple takes a month to grow old and each subsequent month procreates another couple ”(Laurence Sigler, Fibonacci's Liber Abaci, page 404).

The answer to this question is as follows:

  • We started with a couple of rabbits the first month.
  • The second month the couple ages but does not procreate.
  • The third month the couple procreates another couple (that is, we already have two partners).
  • In the fourth month, the first couple procreate again and the new couple ages without procreating (then we have three partners).
  • In the fifth month, the two oldest couples procreate again while the new couple does not procreate (five couples in total)

Starting from the numbers 0 and 1, the Fibonacci numbers are defined  by the function:

fn = (fn - 1) + (fn - 2)
f0 = 0
f1 = 1
f2 = f1 + f0 = 1
f3 = f2 + f1 = 2

Therefore, the simplest and easiest to understand implementation of the fibonacci series in PseInt would be:

Algoritmo SerieFibonacci
	Definir _numero, a, b, tmp como Entero
	
	Escribir "- Serie de Fibonacci -"
    Escribir "	Por favor ingrese la cantidad de números de la serie que se imprimirán:"
    Leer _numero
	
    b = 1
	
    Para i<-1 Hasta _numero Hacer
        Escribir a
        tmp = a + b
        a = b
        b = tmp
    FinPara
FinAlgoritmo

Happy coding ❤️!

Related articles
How to resolve PseInt exception: ERROR 273 Debe haber un Proceso
10 Apr, 2021
  • Estimated reading time: 2 Minutes
How to print the border of an empty square with asterisks in PseInt
20 Oct, 2020
  • Estimated reading time: 1 Minute
How to print the first N multiples of a number in PseInt
20 Oct, 2020
  • Estimated reading time: 1 Minute
How to determine if a number is positive or negative in PseInt
20 Oct, 2020
  • Estimated reading time: 1 Minute
Weekly trending
How Modern Crown Technology Makes Dental Visits Easier
6 Jun, 2026
  • Estimated reading time: 10 Minutes
The Technology Behind Smarter Boat Navigation Systems
6 Jun, 2026
  • Estimated reading time: 2 Minutes
The Future of Human Machine Interfaces Is Simpler Than Ever
6 Jun, 2026
  • Estimated reading time: 2 Minutes
Our Sponsors

Our blog is proudly supported by industry-leading sponsors.