Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace MoreMethodExercises
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Enter the numbers you want to get from a tribonacci sequence: ");
- int num = int.Parse(Console.ReadLine());
- TribonacciSeq(num);
- }
- static void TribonacciSeq(int number)
- {
- int[] arr = new int[number];
- arr[0] = 1;
- arr[1] = 1;
- arr[2] = 2;
- if(number == 1)
- {
- Console.WriteLine("1");
- }
- else if(number == 2)
- {
- Console.WriteLine("1 1");
- }
- else if (number == 3)
- {
- Console.WriteLine("1 1 2");
- }
- else if(number > 3)
- {
- for (int k = 3; k < arr.Length; k++)
- {
- arr[k] = arr[k - 3] + arr[k - 2] + arr[k - 1];
- }
- foreach (int m in arr)
- {
- Console.Write(m + " ");
- }
- }
- else
- {
- Console.WriteLine("Incorrect input");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment