How to calculate the series 1 3 4 8 15 27 50 92 169 311 572 ... N in C#

1 Answer

0 votes
// 1 3 4 8 15 27 50 92 169 311 572 ... N 
 
// (1) (3) (4) : 1 + 3 + 4 (8) : 3 + 4 + 8 (15) : 4 + 8 + 15 (27) :
// 8 + 15 + 27 (50) : 15 + 27 + 50 (92) : 27 + 50 + 92 (169) :
// 50 + 92 + 169 (311) : 92 + 169 + 311 (572)

using System;

class Program
{
    static void Main() {
        int a = 1, b = 3, c = 4, total = 11;
 
        Console.Write("{0} {1} {2} ", a, b, c);
 
        int sum = 0;
        for (int i = 4; i <= total; i++) {
            sum = a + b + c;
            Console.Write("{0} ", sum);
 
            a = b;
            b = c;
            c = sum;
        }
    }
}


 
 
 
/*
run:
 
1 3 4 8 15 27 50 92 169 311 572
 
*/
 

 



answered Mar 30, 2022 by avibootz
...