Help with this problem regarding loopings

Make a program that willl generate n number of items of this sequence given the value of n from keyboard input. The program prints the items of the sequence and its sum.
Algorithm:
the sequence:
1 1 1 3 5 9 17 .....
a. initialize the first three items ; t1=1, t2=1, t3=1 and S=3 ( sum of t1, t2 and t3).
b. the next item t4, in the sequence is determide from the sum of preceding 3 items:
t4=t1+t2+t3 and is also added to the sum, S of the sequence S = S+t4.
c. to generate the next items, t1, t2 ad t3 are reassigned as follows:
t1=t2; t2=t3 and t3=t4.
d. repear steps b and c until n numbers of items of the sequence is generated..


please do it using while loop, do-while loop and for loop.
what code have you written so far? this seems pretty straightforward, just create an array of the sequence and do something like this
 
sequence[++i] = sequence[i] + sequence[i - 1] + sequence[i - 2];


what is your question exactly...?
Topic archived. No new replies allowed.