Add calcul somme tableau
This commit is contained in:
parent
b406c7a431
commit
a85e6f3908
2 changed files with 25 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -38,3 +38,4 @@ adresses-variables
|
|||
pointeurs
|
||||
sos-crash
|
||||
longueur-chaine
|
||||
calcul-somme-tableau
|
||||
|
|
24
programmation-c-cpp/tp4/calcul-somme-tableau.c
Normal file
24
programmation-c-cpp/tp4/calcul-somme-tableau.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/* Calcul somme tableau */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main() {
|
||||
int tableau[100];
|
||||
int *pointeur = tableau;
|
||||
int somme = 0;
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
tableau[i] = i + 1;
|
||||
}
|
||||
|
||||
while (*pointeur != 100) {
|
||||
somme += *pointeur;
|
||||
pointeur++;
|
||||
}
|
||||
somme += *pointeur;
|
||||
|
||||
printf("La somme des valeurs du tableau fait %d\n", somme);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue