Skip to content
Snippets Groups Projects
Verified Commit 6b30b013 authored by orestis.malaspin's avatar orestis.malaspin
Browse files

corrections

parent b301a4ce
No related branches found
No related tags found
No related merge requests found
Pipeline #26850 passed
...@@ -14,12 +14,13 @@ header-includes: | ...@@ -14,12 +14,13 @@ header-includes: |
. . . . . .
```C ```C
int pow(int x, int n) { double pow(double x, int n) {
if (0 == n) { if (0 == n) {
return 1; return 1;
} }
double p = c;
for (int i = 1; i < n; ++i) { for (int i = 1; i < n; ++i) {
x = x * x; // x *= x p = p * x; // x *= x
} }
return x; return x;
} }
...@@ -38,7 +39,7 @@ int pow(int x, int n) { ...@@ -38,7 +39,7 @@ int pow(int x, int n) {
. . . . . .
```C ```C
int pow(x, n) { double pow(double x, int n) {
if (n != 0) { if (n != 0) {
return x * pow(x, n-1); return x * pow(x, n-1);
} else { } else {
...@@ -71,8 +72,8 @@ $$ ...@@ -71,8 +72,8 @@ $$
## Le vrai algorithme ## Le vrai algorithme
* Si n est pair: calculer $\left(x^{n/2}\right)^2$, * Si n est pair: calculer $\left(x^{n/2}\cdot x^{n/2}\right)$,
* Si n est impair: calculer $x \cdot \left(x^{(n-1)/2}\right)^2$. * Si n est impair: calculer $x \cdot \left(x^{(n-1)/2}\right)^2=x\cdot x^{n-1}$.
## Exercice: écrire l'algorithme récursif correspondant ## Exercice: écrire l'algorithme récursif correspondant
...@@ -80,8 +81,8 @@ $$ ...@@ -80,8 +81,8 @@ $$
```C ```C
double pow(double x, int n) { double pow(double x, int n) {
if (1 == n) { if (0 == n) {
return x; return 1;
} else if (n % 2 == 0) { } else if (n % 2 == 0) {
return pow(x, n / 2) * pow(x, n/2); return pow(x, n / 2) * pow(x, n/2);
} else { } else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment