Bootcamps
Masterclasses
Menu
Courses
Account
Login / Sign Up

Fibonacci Series

Easy Acceptance 85% Points 20

Description: You are given a positive integer N. Your task is to generate and print the Fibonacci sequence up to N terms. Display all the terms in order on a single line, separated by spaces.

Examples
Example 1

Example 1

Input: n = 5

Output: 0 1 1 2 3

Explanation: Not Needed

Example 2

Example 2

Input: 7

Output: 0 1 1 2 3 5 8

Explanation: Not Needed

Constraints
  • Constraints: 1<=N<=109
Topics
Recursion
Companies
Microsoft Samsung Deloitte
Added 19 Jul 2026 85% acceptance
Ln 1, Col 1Sign in to save your code
2
0 1