Add puissance

This commit is contained in:
flyingscorpio@pinebookpro 2021-11-29 08:39:26 +01:00
parent 9b2bd53a75
commit f3661a2ff7
2 changed files with 29 additions and 0 deletions

1
.gitignore vendored
View file

@ -39,3 +39,4 @@ pointeurs
sos-crash
longueur-chaine
calcul-somme-tableau
puissance

View file

@ -0,0 +1,28 @@
/* Puissance */
#include <stdio.h>
#include <stdlib.h>
int puissance(int, int);
int main() {
int a, b, p;
a = 2;
b = 3;
p = puissance(a, b);
printf("%d puissance %d = %d\n", a, b, p);
return 0;
}
int puissance(int a, int b) {
int p = 1;
for (int i = 0; i < b; i++) {
p = p * a;
}
return p;
}