C has e
notation for floating point numbers. It has special format specifier %e
and %E
just to print a floating point number in e
notation. But neither the exponents nor mantissa can be variable. .
x = 4.0e7;
is perfectly fine.
But to have variable power you need to use standard math
library functions exp
or pow
.
x = pow(4, k);
or
x = 4 * exp(k);
The way you are using this in a loop, you can optimize it by keeping last calculated value this way: (Assuming x
is initialized to 1
before loop begins.)
x = x * 4;
Every time loop runs x
is multiplied by 4
hence basically at k
th loop run x = 4*exp(k);
.