-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathcode_1.cpp
More file actions
39 lines (35 loc) · 780 Bytes
/
code_1.cpp
File metadata and controls
39 lines (35 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//
// code_1.cpp
// Algorithm
//
// Created by Mohd Shoaib Rayeen on 13/11/18.
// Copyright © 2018 Shoaib Rayeen. All rights reserved.
//
#include <bits/stdc++.h>
using namespace std;
int Jacobsthal(int n) {
if (n == 0) {
return 0;
}
if (n == 1) {
return 1;
}
return Jacobsthal(n - 1) + 2 * Jacobsthal(n - 2);
}
int Jacobsthal_Lucas(int n) {
if (n == 0) {
return 2;
}
if (n == 1) {
return 1;
}
return Jacobsthal_Lucas(n - 1) + 2 * Jacobsthal_Lucas(n - 2);
}
int main() {
int n;
cout << "\nEnter n\t:\t";
cin >> n;
cout << "\nJacobsthal number\t:\t" << Jacobsthal(n) << endl;
cout << "\nJacobsthal-Lucas number\t:\t" << Jacobsthal_Lucas(n) << endl;
return 0;
}