
Problem
Solution
Submissions
Fibonacci Series up to N Terms
Certification: Basic Level
Accuracy: 26.51%
Submissions: 83
Points: 10
Write a C# program that generates the Fibonacci sequence up to N terms.
Example 1
- Input: N = 8
- Output: 0, 1, 1, 2, 3, 5, 8, 13
- Explanation:
- Step 1: Initialize the first two Fibonacci numbers (0 and 1).
- Step 2: Calculate each subsequent number by adding the two previous numbers.
- Step 3: For N = 8, we generate 8 Fibonacci numbers: 0, 1, 1, 2, 3, 5, 8, 13.
- Step 4: Return the sequence as the output.
Example 2
- Input: N = 5
- Output: 0, 1, 1, 2, 3
- Explanation:
- Step 1: Initialize the first two Fibonacci numbers (0 and 1).
- Step 2: Calculate each subsequent number by adding the two previous numbers.
- Step 3: For N = 5, we generate 5 Fibonacci numbers: 0, 1, 1, 2, 3.
- Step 4: Return the sequence as the output.
Constraints
- 1 ≤ N ≤ 10^3
- Time Complexity: O(N)
- Space Complexity: O(N)
Editorial
My Submissions
All Solutions
Lang | Status | Date | Code |
---|---|---|---|
You do not have any submissions for this problem. |
User | Lang | Status | Date | Code |
---|---|---|---|---|
No submissions found. |
Solution Hints
- Initialize sequence with [0, 1]
- Iterate and sum last two numbers to generate next term