diff --git a/Basic/Calculate Nth Tribonacci Number/SolutionByPrabsimar.cpp b/Basic/Calculate Nth Tribonacci Number/SolutionByPrabsimar.cpp new file mode 100644 index 000000000..5dafbaa8b --- /dev/null +++ b/Basic/Calculate Nth Tribonacci Number/SolutionByPrabsimar.cpp @@ -0,0 +1,33 @@ +//Tribonacci series +#include +using namespace std; +int tribonacci(int n) +{ + if (n == 1) { + return 0; + } else if (n == 2) { + return 0; + } else if (n == 3) { + return 1; + } else { + int a = 0; + int b = 0; + int c = 1; + int ans; + for (int i = 4; i <= n; i++) { + ans = a + b + c; + a = b; + b = c; + c = ans; + } + return ans; + } +} +int main() +{ + int num; + cout << "enter the num " << endl; + cin >> num; + cout << tribonacci(num); + return 0; +}