1. Tableaux
Un tableau stocke plusieurs valeurs du même type. Indices à partir de 0.
int notes[5] = {12, 15, 8, 19, 10};
printf("%d\n", notes[2]); // 8
Un tableau stocke plusieurs valeurs du même type. Indices à partir de 0.
int notes[5] = {12, 15, 8, 19, 10};
printf("%d\n", notes[2]); // 8
Une chaîne est un tableau de char terminé par '\0'.
char nom[20] = "Alice";
printf("%s, longueur = %lu\n", nom, strlen(nom));
strlen, strcpy, strcat, strcmp manipulent les chaînes.
Trouver le plus grand élément d'un tableau de 10 entiers.
int max = t[0];
for (int i = 1; i < 10; i++)
if (t[i] > max) max = t[i];
Écrire une fonction qui inverse une chaîne en place.
void inverser(char *s) {
int n = strlen(s);
for (int i = 0; i < n/2; i++) {
char tmp = s[i];
s[i] = s[n-1-i];
s[n-1-i] = tmp;
}
}