Friday, May 21, 2010

How do you write exponents in c Programming?

lets say to the 12th power

How do you write exponents in c Programming?
#include %26lt;math.h%26gt;


....


y = pow(x, 12);
Reply:Under the assumption that you are using a linux box for your programming... The below example should give you a clear picture.





#include %26lt;math.h%26gt;





int main()


{


printf("3 to the power of 12 equals: %f\n",pow(3,12));


}





To compile ( Ensure to link the math library )


gcc exp.c -lm





To run


./a.out
Reply:use the pow(int,int) function, defined in math.h





Ex: (takes x to the fifth power)





#include %26lt;math.h%26gt;


#include %26lt;iostream%26gt;


using namespace std;


int main() {


int x = 5;


cout%26lt;%26lt;pow(x,5)%26lt;%26lt;endl;


return;


}
Reply:pow() function in math.h (there is no operator for exponentiation)

song lyrics

No comments:

Post a Comment