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

16,262

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.

Share:
16,262
Milad R
Author by

Milad R

Hi!

Updated on July 11, 2022

Comments

  • Milad R
    Milad R almost 2 years

    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?