# Finding the algorithm that's right for you.

This is a discussion on Finding the algorithm that's right for you. within the A Brief History of Cprogramming.com forums, part of the Community Boards category; 1 2 3 4 5 6 7 8 9 10 1 2 4 8 16 32 64 128 256 512 ...

1. ## Finding the algorithm that's right for you.

1 2 3 4 5 6 7 8 9 10
1 2 4 8 16 32 64 128 256 512

I need an equation that takes a number from the top row as it's only variable, and produces the corresponding number on the bottom. You can also move them around, like have 0 above the 2 or something, but just tell me which direction you moved which bar how far. I just need a starting point. i tried finding the differences but it just turns into circular logic.

2. Well, if you had this

0 1 2 3 4 5 6 7 8 9 10
1 2 4 8 16 32 64 128 256 512

Then it's just pow(2,n)

Two, to the power of the number on the top row, gives you the number on the bottom row

3. A post in straight C from me... don't get these so often . It's a simple function you want.

Code:
```#include <stdio.h>

int main(int argc, char *argv[])
{
for (int i = 1; i < 11; i++) {
printf("Input is %i, output is is %i \n", i, 1 << (i - 1));
}
getchar();
return 0;
}```

4. The annoying thing is, as soon as I logged off after posting this, I figured it out. Murphy's Law I guess.