Advertisement
Siropo

Tribonacci triangle

Dec 30th, 2012
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1. using System;
  2.  
  3. class Tribonacci
  4. {
  5.     static void Main()
  6.     {
  7.         long firstNum = long.Parse(Console.ReadLine());
  8.         long secondNum = long.Parse(Console.ReadLine());
  9.         long thirdNum = long.Parse(Console.ReadLine());
  10.  
  11.         long rows = long.Parse(Console.ReadLine());
  12.         long finalSum = 0;
  13.         Console.WriteLine(firstNum + "\n" + secondNum + " " + thirdNum);
  14.         for (long i = 2; i < rows; i++)
  15.         {
  16.             for (long j = 0; j < i + 1 ; j++)
  17.             {
  18.                 long temp1 = firstNum; // 1
  19.                 long temp2 = secondNum; // -1
  20.                 long temp3 = thirdNum; // 1
  21.                 long temp4 = finalSum; // 1 1
  22.  
  23.                 if (j == 0 && i == 2)
  24.                 {
  25.                     temp4 = thirdNum;
  26.                     temp3 = secondNum;
  27.                 }
  28.  
  29.                 finalSum += firstNum + secondNum + thirdNum;
  30.  
  31.                 firstNum = 0;
  32.                 secondNum = temp3;
  33.                 thirdNum = temp4;
  34.  
  35.                 Console.Write(finalSum + " ");
  36.             }
  37.             Console.WriteLine();
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement