diff options
Diffstat (limited to 'sem_2/HLIN202/TP/TP7-8/ex6/exo6.cpp')
| -rw-r--r-- | sem_2/HLIN202/TP/TP7-8/ex6/exo6.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/sem_2/HLIN202/TP/TP7-8/ex6/exo6.cpp b/sem_2/HLIN202/TP/TP7-8/ex6/exo6.cpp new file mode 100644 index 0000000..c0c36ef --- /dev/null +++ b/sem_2/HLIN202/TP/TP7-8/ex6/exo6.cpp @@ -0,0 +1,16 @@ +#include<iostream>
+
+int occurence ( int T[10], int x) {
+ int cpt=0;
+ for ( int i=0; i < 10; i ++) {
+ cpt += T[i]==x ? 1 : 0;
+ }
+ return cpt;
+}
+int main () {
+ int tab[10]= {2,3,4,2,3,1,8,2,5,9};
+ int x=0;
+ std::cout<< " Entrez un entier positif, ce programme calcule le nombre d'occurence de cet entier dans le tableau [2 3 4 2 3 1 8 2 5 9]" << std::endl;
+ std::cin>>x;
+ std::cout<<x << " est present " << occurence(&tab[0], x) << " fois dans le tableau "<<std::endl;
+}
|
