Program to print first 10 numbers of Fibonacci series Last Updated : 21 Feb, 2024 Comments Improve Suggest changes Like Article Like Report Find the first 10 numbers of Fibonacci series. The Fibonacci sequence is a sequence where the next term is the sum of the previous two terms. The first two terms of the Fibonacci sequence are 0 followed by 1. The Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, ........ Approach: To solve the problem, follow the below idea: We can take two variables f1 and f2 to store the first and second term. In order to calculate the next terms, we can take the sum of previous two terms f1 and f2 and then update f1 with f2 and f2 with the new term. Repeat for 10 times to get first 10 numbers of Fibonacci Sequence. Step-by-step algorithm: Use two variables f1 and f2 and initialize with 0 and 1 respectively because the 1st and 2nd elements of the Fibonacci series are 0 and 1 respectively. Iterate from 1 to 9 as we have to print first 10 numbers and print f2 then store f2 in temp variable and update f2 with f2 + f1 and f1 as f2.Below is the implementation of the approach: C++ // C++ program to print // first 10 Fibonacci numbers #include <bits/stdc++.h> using namespace std; // Function to print // first 10 Fibonacci Numbers void printFibonacciNumbers(int n) { int f1 = 0, f2 = 1, i; if (n < 1) return; cout << f1 << " "; for (i = 1; i < n; i++) { cout << f2 << " "; int next = f1 + f2; f1 = f2; f2 = next; } } // Driver Code int main() { printFibonacciNumbers(10); return 0; } Java public class Fibonacci { // Function to print first n Fibonacci Numbers static void printFibonacciNumbers(int n) { int f1 = 0, f2 = 1; if (n < 1) return; System.out.print(f1 + " "); for (int i = 1; i < n; i++) { System.out.print(f2 + " "); int next = f1 + f2; f1 = f2; f2 = next; } } // Driver code public static void main(String[] args) { printFibonacciNumbers(10); } } Python3 # Function to print first n Fibonacci numbers def print_fibonacci_numbers(n): f1, f2 = 0, 1 if n < 1: return print(f1, end=" ") for i in range(1, n): print(f2, end=" ") next_fibonacci = f1 + f2 f1, f2 = f2, next_fibonacci # Driver Code if __name__ == "__main__": print_fibonacci_numbers(10) C# using System; class Program { // Function to print first n Fibonacci Numbers static void PrintFibonacciNumbers(int n) { int f1 = 0, f2 = 1; if (n < 1) return; Console.Write(f1 + " "); for (int i = 1; i < n; i++) { Console.Write(f2 + " "); int next = f1 + f2; f1 = f2; f2 = next; } } // Main Method static void Main() { // Calling the function to print first 10 Fibonacci Numbers PrintFibonacciNumbers(10); // Ensure the console window stays open Console.ReadLine(); } } JavaScript // Function to print first n Fibonacci numbers function print_fibonacci_numbers(n) { let f1 = 0, f2 = 1; if (n < 1) { return; } console.log(f1); for (let i = 1; i < n; i++) { console.log(f2); const next_fibonacci = f1 + f2; f1 = f2; f2 = next_fibonacci; } } // Driver Code print_fibonacci_numbers(10); Output0 1 1 2 3 5 8 13 21 34 Time Complexity: O(10) ~ O(1)Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article Program to print first 10 numbers of Fibonacci series S sumaiygs7h Follow Improve Article Tags : DSA Scala-Arrays Volkswagen IT Services Similar Reads Program to Print Fibonacci Series Ever wondered about the cool math behind the Fibonacci series? This simple pattern has a remarkable presence in nature, from the arrangement of leaves on plants to the spirals of seashells. We're diving into this Fibonacci Series sequence. It's not just math, it's in art, nature, and more! Let's dis 8 min read Program to find Prime Fibonacci Numbers till N Given a number, find the numbers (smaller than or equal to n) which are both Fibonacci and prime.Examples: Input : n = 40 Output: 2 3 5 13 Explanation : Here, range(upper limit) = 40 Fibonacci series upto n is, 1, 1, 2, 3, 5, 8, 13, 21, 34. Prime numbers in above series = 2, 3, 5, 13. Input : n = 10 8 min read Program to find last digit of n'th Fibonacci Number Given a number 'n', write a function that prints the last digit of n'th ('n' can also be a large number) Fibonacci number. Examples : Input : n = 0 Output : 0 Input: n = 2 Output : 1 Input : n = 7 Output : 3 Recommended PracticeThe Nth FibonnaciTry It! Method 1 : (Naive Method) Simple approach is to 13 min read Program to find Nth odd Fibonacci Number Given an integer N. The task is to find the Nth odd Fibonacci number.The odd number fibonacci series is as: 1, 1, 3, 5, 13, 21, 55, 89, 233, 377, 987, 1597.............and so on.Note: In the above series we have omitted even terms from the general fibonacci sequence. Examples: Input: N = 3 Output: 3 3 min read Program for Fibonacci numbers in PL/SQL The Fibonacci numbers are the numbers in the following integer sequence. 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, â¦â¦.. In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation Fn = Fn-1 + Fn-1 with seed values F0= 0 and F1 = 1. Given a number n, print n- 1 min read Like