Skip to content

Commit

Permalink
Create Fibonacci series up to Nth term
Browse files Browse the repository at this point in the history
  • Loading branch information
dishathakurata authored Mar 23, 2024
1 parent a9f463d commit d389136
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Fibonacci series up to Nth term
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;
}
}

0 comments on commit d389136

Please sign in to comment.