C++/C++ exponents
Expert: Prince M. Premnath - 6/17/2009
QuestionHow do you write exponents in C++ code? I've been trying to find out but it has me confused.
AnswerHi Dear Melissa!
Writing Exponents in programming languages is different from math notations since the compiler some times would not understand the notations or its will interpret the symbols in its own format.
say if you want to write a simple exponent (x+1)^y in C++ , straight away you should not write the same code , if so the above statement will be interpreted as (x+1) XOR y (which is not the one we require !)
the right form is usage of built in function pow() available in math.h header file , the above statement should be written as
#include <math.h>
....
..
..
pow(x + 1, y);
.
.
.
Note: if you are dealing with some advanced concepts with exponents , please let me know!
Thanks and Regards!
Prince M. Premnath