Computer Science Canada

Using exponents

Author:  Ceevu [ Mon May 22, 2006 1:31 am ]
Post subject:  Using exponents

I use the MinGW 4.1 compiler and run in WinXP.

As for the Q:

I'm wondering what notation I would use to write exponents in C?

An example I'm working on is writing a program that calculates the volume of a sphere. Formula is: 4/3*pi*radius(cubed).


cheers and thanks in advance

Author:  [Gandalf] [ Mon May 22, 2006 1:59 am ]
Post subject: 

There is no exponent operator in C or C++, instead you can use the pow() function in math.h.
An example of usage:
c:
#include <stdio.h>
#include <math.h>

int main()
{
   printf("%d\n", (int)pow (5.0, 3.0)); //returns 5^3
   return 0;
}

Author:  Ceevu [ Mon May 22, 2006 11:39 am ]
Post subject: 

Thanks a lot, Gandalf!


: