77 lines
1.4 KiB
C
Executable file
77 lines
1.4 KiB
C
Executable file
#include <stdio.h>
|
|
void select(int* tableau);
|
|
int compter_zero(int tableau[]);
|
|
int compter_un(int tableau[]);
|
|
void compter_N(int tableau[]);
|
|
|
|
int exo4(void)
|
|
{
|
|
int tab[10];
|
|
select(&tab[0]);
|
|
//zero=compter_zero(&tab[0]);
|
|
//printf("Il y a %d zeros dans le tableau",zero);
|
|
compter_N(tab); // tab ou &tab[0] donnent la même chose.
|
|
return 0;
|
|
}
|
|
|
|
void select(int* tableau)
|
|
{
|
|
int i;
|
|
for(i=0; i<10; i++)
|
|
{
|
|
do
|
|
{
|
|
printf("\nEntrez 10 nombres :");
|
|
scanf("%d",&tableau[i]);
|
|
}
|
|
while(tableau[i]< -5 || tableau[i]> 5);
|
|
};
|
|
}
|
|
|
|
int compter_zero(int tableau[])
|
|
{
|
|
int i;
|
|
int nbr = 0;
|
|
for(i=0; i<10; i++)
|
|
{
|
|
if(tableau[i]==0)
|
|
{
|
|
nbr = nbr+1;
|
|
};
|
|
};
|
|
return nbr;
|
|
}
|
|
|
|
int compter_un(int tableau[])
|
|
{
|
|
int i;
|
|
int nbr = 0;
|
|
for(i=0; i<10; i++)
|
|
{
|
|
if(tableau[i]==1 || tableau[i]==-1)
|
|
{
|
|
nbr = nbr+1;
|
|
};
|
|
};
|
|
return nbr;
|
|
}
|
|
|
|
void compter_N(int tableau[])
|
|
{
|
|
int i;
|
|
int nbr = 0;
|
|
int x;
|
|
for(x=0; x<=5; x++)
|
|
{
|
|
for(i=0; i<10; i++)
|
|
{
|
|
if(tableau[i]==x || tableau[i]==-x)
|
|
{
|
|
nbr = nbr+1;
|
|
};
|
|
};
|
|
printf("\nIl y a %d [%d,-%d]",nbr,x,x);
|
|
nbr=0;
|
|
};
|
|
}
|
|
|