Java
This commit is contained in:
26
DEV1.1/CM3/bilan.c
Normal file
26
DEV1.1/CM3/bilan.c
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
int nb_negatifs(int* tab, size_t taille_tab) {
|
||||
if (taille_tab == 0) {
|
||||
return 0;
|
||||
}
|
||||
return (tab[taille_tab-1] < 0) + nb_negatifs(tab, taille_tab-1);
|
||||
}
|
||||
|
||||
|
||||
int main(void) {
|
||||
int tab_1[5]; /* Vide */
|
||||
int tab_2[5] = {2, 4, 1, 38, 0}; /* Positif ou nul */
|
||||
int tab_3[5] = {-2, -7, -20, -829, -1000}; /* Strictement négatif */
|
||||
int tab_4[5] = {3, -7, 11, 0, -50}; /* Signe divers et au moins une valeur nulle */
|
||||
|
||||
printf("%d\n", nb_negatifs(tab_1, 5));
|
||||
printf("%d\n", nb_negatifs(tab_2, 5));
|
||||
printf("%d\n", nb_negatifs(tab_3, 5));
|
||||
printf("%d\n", nb_negatifs(tab_4, 5));
|
||||
|
||||
for
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Reference in New Issue
Block a user