Menentukan Barisan Tribonacci Dengan Array C# Posted by Unknown on January 14, 2015 Get link Facebook X Pinterest Email Other Apps Dengan keterangan program : - Input berupa : Jumlah Suku. - Setiap nilai suku akan disimpan ke dalam Array. - Rumus Tribonacci yang digunakan : Suku-1 = suku-2 = suku-3 = 1 Tribo (N) = Tribo (N – 3) + Tribo (N – 2) + Tribo (N – 1) using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MODUL5_2 { class Program { static void Main(string[] args) { int[] tribo = new int[0]; int bilangan; Console.Write("Jumlah suku Tribonacci = "); bilangan = Convert.ToInt32(Console.ReadLine()); for (int i = 0; i < bilangan; i++) { Array.Resize(ref tribo, tribo.Length + 1); if (i == 0 || i == 1 ||i==2) { tribo[i] = 1; Console.Write(tribo[i] + " "); } else { tribo[i] =tribo[i - 3]+ tribo[i - 2] + tribo[i - 1]; Console.Write(tribo[i] + " "); } } Console.ReadKey(); } } } Comments
Comments
Post a Comment