C/Math/Power
Calculate numeric power: how to use pow
#include <stdio.h>
#include <math.h>
int main ()
{
printf ("7 ^ 3 = %lf\n", pow ( 7 , 3 ) );
printf ("5.73 ^ 12 = %lf\n", pow (5.73, 12 ) );
printf ("31.01 ^ 1.54 = %lf\n", pow (31.01, 1.54));
return 0;
}
How to use pow
#include <math.h>
#include <stdio.h>
int main(void)
{
double x = 10.0, y = 0.0;
do {
printf("%f\n", pow(x, y));
y++;
} while(y<11.0);
return 0;
}
Our own power function
#include <stdio.h>
int power(void);
int m, e;
int main(void)
{
m = 2;
e = 3;
printf("%d raised to the %d power = %d", m, e, power());
return 0;
}
int power(void)
{
int temp, temp2;
temp = 1;
temp2 = e;
for( ; temp2> 0; temp2--)
temp = temp * m;
return temp;
}