# Help with powers

This is a discussion on Help with powers within the C Programming forums, part of the General Programming Boards category; Can anyone tell me how to output code that shows the power of 2 all the way up to 2 ...

1. ## Help with powers

Can anyone tell me how to output code that shows the power of 2 all the way up to 2 to the 10th power and have it show on one line? i know that the code for power is pow(x,y) but don't know exactly how to use it. Thanks

2. for ( i = 0 ; i < 10 ; i++ ) pow( 2, i );

The rest is pretty printing

3. You could just not use the pow function. Since you're doing the powers of two you can shift bits around with the same result.
Code:
```unsigned x, n;
for ( x = 0, n = 1; x < 10; x++, n <<= 1 )
printf ( "%u ", n );```
Simple.

-Prelude

4. Found this one in my book.... it might help someone
Code:
```#include <stdio.h>
#define TWO_TO_THE(x) (1L <<(x))
#define FOUR_TO_THE(x) (1L <<((x) <<1))

int main(void)
{
printf("%ld\n", FOUR_TO_THE(3));
printf("%ld\n", TWO_TO_THE(10));
return (0);
}```