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
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
for ( i = 0 ; i < 10 ; i++ ) pow( 2, i );
The rest is pretty printing
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.
Simple.Code:unsigned x, n; for ( x = 0, n = 1; x < 10; x++, n <<= 1 ) printf ( "%u ", n );
-Prelude
My best code is written with the delete key.
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); }
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]