C/Math/Power — различия между версиями
Admin (обсуждение | вклад) м (1 версия: Импорт контента...) |
(нет различий)
|
Текущая версия на 13:22, 25 мая 2010
Calculate numeric power: how to use pow
<source lang="cpp">
- 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;
}
</source>
How to use pow
<source lang="cpp">
- 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;
}
</source>
Our own power function
<source lang="cpp">
- 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;
}
</source>