Advertisement
CR7CR7

Tribonachi

Oct 12th, 2022
638
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.51 KB | None | 0 0
  1. import java.util.Scanner;
  2. class Program {
  3.     static void Main(string[] args) {
  4.         Scanner sc =new Scanner(System.in);
  5.         int n1 = 0;
  6.         int n2 = 0;
  7.         int n3 = 1;
  8.         int n = Integer.parseInt(sc.nextLine());
  9.         if (n > 0) {
  10.             System.out.println(1 + " ");
  11.         }
  12.         for (int i = n; i > 1; --i) {
  13.             int num = n1 + n2 + n3;
  14.             System.out.println(num + " ");
  15.             n1 = n2;
  16.             n2 = n3;
  17.             n3 = num;
  18.         }
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement