Add puissance
This commit is contained in:
parent
9b2bd53a75
commit
f3661a2ff7
2 changed files with 29 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -39,3 +39,4 @@ pointeurs
|
|||
sos-crash
|
||||
longueur-chaine
|
||||
calcul-somme-tableau
|
||||
puissance
|
||||
|
|
28
programmation-c-cpp/tp5/puissance.c
Normal file
28
programmation-c-cpp/tp5/puissance.c
Normal 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;
|
||||
}
|
Loading…
Reference in a new issue