Vous êtes sur la page 1sur 2

LAMHOUR MOHAMED AKRAM

M1 DSBD 2020/2021

➢ Exercice 1 : Ecrire un programme qui cherche le minimum d’un tableau.

public int Min(int[] t)

int posmin=0;

for (int i = 1; i < t.Length; i++)

if (t[posmin]>t[i])

posmin=i;

return t[posmin];

➢ Exercice 2 : Ecrire un programme qui compte le nombre d’occurrences d’un nombre donné
dans un tableau.

public int NombreOccurrences (int[] t, int x)

int nb=0;

for (int i = 0; i < t.Length; i++)

if (t[i] == x)

nb++;

return nb ;

➢ Exercice 3 : Ecrire un programme qui compte le nombre de nombres impairs dans un tableau.

public int NombresImpairs (int[] t)

int nb=0;

for (int i = 0; i < t.Length; i++)

if (t[i]%2 != 0)

nb+=1;

return nb ;

}
LAMHOUR MOHAMED AKRAM
M1 DSBD 2020/2021

➢ Exercice 4 : Ecrire un programme qui cherche un nombre dans un tableau.

public bool Chercher(int[] t, int x)

for (int i = 0; i < t.Length; i++)

if (t[i] == x)

return true;

return false ;

➢ Exercice 5 : Ecrire un programme qui retourne sous forme d’un tableau les nombres impairs
dans un tableau.

public int[] TabNombresImpairs (int[] t)

int taille = NbImp(t);

int j=0;

int[] tab = new int[taille];

for (int i = 0; i < t.Length; i++)

if (t[i]%2 != 0)

tab[j]=t[i];

j++;

return tab;

➢ Exercice 6 : Ecrire un programme qui permet de trier un tableau

public void Trier(int [] t)

Array.Sort(t);

Vous aimerez peut-être aussi