-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Fibonacci series up to Nth term
- Loading branch information
1 parent
a9f463d
commit d389136
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//Fibonacci series up to Nth term | ||
|
||
import java.io.*; | ||
import java.util.*; | ||
|
||
class Main { | ||
|
||
public static void main(String[] args) throws Exception { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
int t = Integer.parseInt(br.readLine().trim()); | ||
|
||
while(t-- > 0) { | ||
int n = Integer.parseInt(br.readLine().trim()); | ||
Solution obj = new Solution(); | ||
int ans[] = obj.Series(n); | ||
|
||
for(int i : ans) { | ||
System.out.print(i + " "); | ||
} | ||
System.out.println(); | ||
} | ||
} | ||
} | ||
|
||
class Solution { | ||
|
||
int[] Series(int n) { | ||
int[] fib = new int[n + 1]; | ||
|
||
fib[0] = 0; | ||
fib[1] = 1; | ||
|
||
int mod = 1000000007; | ||
for(int i = 2; i <= n; i++) { | ||
fib[i] = (fib[i - 1] + fib[i - 2]) % mod; | ||
} | ||
|
||
return fib; | ||
} | ||
} |