Write a program to generate first 20 terms of Fibonacci series and store them in single dimension array. Display the prime Fibonacci numbers from the array
Answers
Answer:
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Got it!
Sign In
Problems
Courses
Get Hired
Discussion
Back To Explore Page
Midori and chocolates
Remainder Evaluation
Matching Pair
Learning Structs
BigInteger Multiply
C++ Input / Output
Operations on PriorityQueue
Addition of Two Numbers
Sum of elements in a matrix
Sum of Big Integers
Maximum Area Rectangle
Delete Array
Java Collections | Set 7 (LinkedList)
1's Complement
Queue Operations
Sort and Reverse Vector
Special Series Sum
Pair Sum in Vector
Set Bits
Mean
Swap the objects
Java Inheritance
Maximum money
Java Hello World
Two Dimensional World
Print first letter of every word in the string
Red OR Green
Back to Front
Front to Back
Learn to Comment
Frequency Game
Sum Of Digits
Mrs. S- JAVA Bits Set 1
Magic in CPP
Queue Push & Pop
Odd or Even
Learning Macros
C++ Generic sort
Min Heap implementation
Multiplication Table
Problem
Editorial
Submissions
Doubt Support
Print first n Fibonacci Numbers
Basic Accuracy: 22.9% Submissions: 76617 Points: 1
Given a number N, print the first N Fibonacci numbers.
Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. The first line of each test case contains the integer N.
Output:
Print the first n fibonacci numbers with a space between each number. Print the answer for each test case in a new line.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<= T <=100
1<= N <=84
Example:
Input:
2
7
5
Output:
1 1 2 3 5 8 13
1 1 2 3 5
Explanation: Some of the numbers of the Fibonacci numbers are 1, 1, 2, 3, 5, 8, 13 ..... (N stars from 1).
Company Tags
Topic Tags
Login to report an issue on this page.
Answer:
class Main {
public static void main(String[] args) {
int n = 10, firstTerm = 0, secondTerm = 1;
System.out.println("Fibonacci Series till " + n + " terms:");
for (int i = 1; i <= n; ++i) {
System.out.print(firstTerm + ", ");
// compute the next term
int nextTerm = firstTerm + secondTerm;
firstTerm = secondTerm;
secondTerm = nextTerm;
}
}
}