Fibonacci Series h

By : cs

Language: javascript

Date Published: 1 week, 6 days ago

The Fibonacci series is one of the most fascinating patterns in mathematics — and it shows up everywhere, from flower petals to galaxy spirals. It’s named after Leonardo Fibonacci, an Italian mathematician who introduced this sequence to Western mathematics in the 13th century.

Style : Dark Mode : Line Number: Download Font Size:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# Program to generate Fibonacci series up to n terms
      def fibonacci(n):
          # The first two terms are fixed
          a, b = 0, 1
          series = []

          # Generate n terms
          for _ in range(n):
              series.append(a)
              a, b = b, a + b  # Move forward in the series

          return series

      # Example usage
      n = int(input("Enter the number of terms: "))
      print("Fibonacci Series:", fibonacci(n))
Login to see the comments