0

How to write power of e in c++? Like e^3, does computer know e?
Can I write it as pow(e,3) ?

Thanks a lot.

3
Contributors
5
Replies
6
Views
10 Years
Discussion Span
Last Post by John A
0

How to write power of e in c++? Like e^3, does computer know e?
Can I write it as pow(e,3) ?

What do you think? Try it.

0

What do you think? Try it.

error: `e' undeclared (first use this function)

Can you tell me how to write it? I tried it, but it is wrong.

0

Are you just starting C now?

>error: `e' undeclared (first use this function)

This means that the compiler's never seen the variable e before. You have to declare it first, and initalize it for it to be any good.

Can you tell me how to write it? I tried it, but it is wrong. The line you wrote previously was correct. But you have to declare a variable first: int e = 0; In the above example, I created 'e' and initalized it with 0. Thus, pow(e, 3) will result in a 0.

0

I think you're looking for something like this:

#include <iostream>
#include <cmath>

int main()
{
  std::cout << M_E << std::endl;
  std::cout << std::pow(M_E, 3) << std::endl;
  return 0;
}
0

Oh sorry, I'm a little bit ignorant of the mathematical constant e . I completely thought he/she was referring to a variable. My apologies :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.