Forumla for this sequence

Soldato
Joined
12 Jun 2005
Posts
5,361
Hi there,

I am rubbish at maths, does anyone know/can work out the formula for this sequence?

1,2,4,8,16,32,64,128,256.......

i want to be able to get the nth term.

Thanks.

EDIT:

Is there even a formula.
 
Last edited:
Conrad11 said:
Could you please explain what is going on there?

It prints out your sequence :)

You start with 1. You times it by 2, you get 2, you print 2. Now you're at 2, you times it by 2, you get 4 and print 4, now you take your four and times them by 2, giving you 8, etc etc etc :)
 
Ex-RoNiN said:
for (x=1; x<n; x++)
{
x=x*2;
printf(x);
}

You realise that is so wrong on so many levels. Even if he was asking for the code for it.
 
Zogger said:
I'm thinking that would print 2,6,14,30...

Nah it would segmentation fault before it even got that far, since printf takes a const char* :p

If you ignore that,

Say n = 6,

First iteration, x=1, x < n; x++ : x = x * 2 = 2. 2 Prints 2, Incremented by 1 = 3.
Second Iteration 3 < 6 true. 3*2 = 6 Prints 6. Increments 6++.
Terminates there.

So 2,6 etc.. yeah :)
 
Last edited:
Back
Top Bottom