Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class TribonacciNthElement
- {
- static void Main()
- {
- //Telerik Academy
- //The Tribonacci sequence is a sequence in which every next element is made by the sum of the previous three elements from the sequence.
- //Write a computer program that finds the Nth element of the Tribonacci sequence, if you are given the first three elements of the sequence and the number N. Mathematically said: with given T1, T2 and T3 – you must find Tn.
- int smallest = int.Parse(Console.ReadLine());
- int middle = int.Parse(Console.ReadLine());
- int biggest = int.Parse(Console.ReadLine());
- int n = int.Parse(Console.ReadLine());
- for (int i = 4; i <= n; i++)
- {
- int next = smallest + middle + biggest;
- smallest = middle;
- middle = biggest;
- biggest = next;
- }
- Console.WriteLine(biggest);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement