Search code examples
c++notation

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


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?


Solution

  • 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.