How to use scientific notation with variable in C++?

Milad R picture Milad R · Nov 24, 2012 · Viewed 15.5k times · Source

I wanna know if it is possible to use the scientific notation with variables?

For example:

int n;
cin >> n;
int x = 1en;

instead of

int x = 1e8

Is it possible? If yes, how?

Answer

Zeta picture Zeta · Nov 24, 2012

No. Scientific notation is only for constant values. Those values are determined at compile time, while the value you want to get is determined at runtime.

You'll have to use something like int result = pow(10,n). Keep in mind that std::pow returns double values.