Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

notation

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?

like image 731
Milad R Avatar asked Nov 24 '12 11:11

Milad R


1 Answers

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.

like image 197
Zeta Avatar answered Oct 01 '22 04:10

Zeta