We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5ed5b25 commit 6f08f89Copy full SHA for 6f08f89
Operators and For Loop:Nth Fibonacci Number
@@ -0,0 +1,35 @@
1
+import java.util.Scanner;
2
+public class Solution {
3
+public static void main(String[] args) {
4
+Scanner s=new Scanner(System.in);
5
+int N=s.nextInt();
6
+ int i;
7
+ int new_term=0;
8
+ int t1=1;
9
+ int t2=1;
10
+
11
+ if(N==1)
12
+ {
13
+ new_term=1;
14
+ }
15
+ else if(N==2)
16
17
18
19
+ else
20
21
+ for(i=3;i<=N;i++)
22
23
+ new_term = t1 + t2;
24
+ t1 = t2;
25
+ t2=new_term;
26
27
28
29
30
31
+ System.out.println(new_term);
32
33
34
+}
35
0 commit comments