We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 042ded2 + db86335 commit 63cf065Copy full SHA for 63cf065
NthFibonacci/NthFibonacci.cpp
@@ -0,0 +1,33 @@
1
+#include <iostream>
2
+
3
+/* Function declaration */
4
+int getNthValue(int n);
5
6
+/* Program starts here */
7
+int main()
8
+{
9
+ int nth; // the Nth number
10
+ std::cout << "Enter the number of term to be printed: " << std::endl;
11
12
+ std::cin >> nth;
13
+ std::cout << getNthValue(nth) << std::endl;
14
15
+}
16
17
+/* Function definition */
18
+int getNthValue(int n)
19
20
+ /* Initial values */
21
+ int a = 1;
22
+ int b = 0;
23
+ int c;
24
25
+ /* Calculate the sequence untill the Nth number */
26
+ for (int i = 0; i <n; i++)
27
+ {
28
+ c = a + b;
29
+ a = b;
30
+ b = c;
31
+ }
32
+ return c; // return the desired number
33
0 commit comments