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)

#include <stdio.h>

int main()
{
    int a = 1, b = 3, c = 4, total = 11;

    printf("%d %d %d ", a, b, c);

    int sum = 0;
    for (int i = 4; i <= total; i++) {
        sum = a + b + c;
        printf("%d ", sum);

        a = b;
        b = c;
        c = sum;
    }

    return 0;
}



/*
run:

1 3 4 8 15 27 50 92 169 311 572 

*/

 



answered Mar 29, 2022 by avibootz
...