Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/halilozel1903/kotlinfibonacciseries
Kotlin Program to Display Fibonacci Series. 💥 3️⃣ 5️⃣ 🎱
https://github.com/halilozel1903/kotlinfibonacciseries
fibonacci fibonacci-generator fibonacci-heap fibonacci-numbers fibonacci-sequence kotlin kotlin-android kotlin-beginner kotlin-example kotlin-examples kotlin-language kotlin-tutorial
Last synced: about 2 months ago
JSON representation
Kotlin Program to Display Fibonacci Series. 💥 3️⃣ 5️⃣ 🎱
- Host: GitHub
- URL: https://github.com/halilozel1903/kotlinfibonacciseries
- Owner: halilozel1903
- Created: 2023-04-01T23:19:38.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-11-05T14:21:08.000Z (about 1 year ago)
- Last Synced: 2024-05-02T02:10:08.202Z (8 months ago)
- Topics: fibonacci, fibonacci-generator, fibonacci-heap, fibonacci-numbers, fibonacci-sequence, kotlin, kotlin-android, kotlin-beginner, kotlin-example, kotlin-examples, kotlin-language, kotlin-tutorial
- Language: Kotlin
- Homepage: https://medium.com/@halilozel1903/membership
- Size: 5.86 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Kotlin Fibonacci Series 🎳 🤯 👁️
![Kotlin Fibonacci Series](https://kotlinlang.org/assets/images/open-graph/general.png)
The `Fibonacci` series is a sequence of numbers where each number is the sum of the two preceding numbers. The first two numbers of the series are 0 and 1, and the subsequent numbers are calculated by adding the previous two numbers.
Here's a `Kotlin` program to display the Fibonacci series up to a specified number of terms:
```kotlin
fun main() {
val range = 10 // specify the number of terms
var firstNumber = 0
var secondNumber = 1print("Fibonacci Series up to $range terms: ")
for (index in 1..range) {
print("$firstNumber - ")val total = firstNumber + secondNumber
firstNumber = secondNumber
secondNumber = total
}
}
```
In this program, we first declare the number of terms we want to display (in this case, range is set to 10). We then initialize two variables `firstNumber` and `secondNumber` with the first two numbers of the series.We use a for loop to iterate through the series up to the specified number of terms. Inside the loop, we print the value of firstNumber and then calculate the next number in the series by adding firstNumber and secondNumber. We then update the values of `firstNumber` and `secondNumber` so that secondNumber becomes the current number in the series and firstNumber becomes the previous number.
The output of this program will be:
```kotlin
Fibonacci Series up to 10 terms: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34,
```