diff options
| author | Gaspard Coulet <gaspard.coulet@mines-ales.org> | 2021-04-28 23:05:53 +0200 |
|---|---|---|
| committer | Gaspard Coulet <gaspard.coulet@mines-ales.org> | 2021-04-28 23:05:53 +0200 |
| commit | 9fe033ea88c2f705ec18c232873d056e0c229d72 (patch) | |
| tree | 0647dc8c51610c7336c88c04de2068ea14b21e17 /sem_2/HLIN202/TP/TP3-4 | |
Initial commit
Diffstat (limited to 'sem_2/HLIN202/TP/TP3-4')
| -rw-r--r-- | sem_2/HLIN202/TP/TP3-4/bonus/bonus.cpp | 33 | ||||
| -rw-r--r-- | sem_2/HLIN202/TP/TP3-4/bonus/prog | bin | 0 -> 9263 bytes | |||
| -rw-r--r-- | sem_2/HLIN202/TP/TP3-4/ex11/exo11 | bin | 0 -> 9336 bytes | |||
| -rw-r--r-- | sem_2/HLIN202/TP/TP3-4/ex11/exo11.cpp | 21 | ||||
| -rw-r--r-- | sem_2/HLIN202/TP/TP3-4/ex12/exo12 | bin | 0 -> 9342 bytes | |||
| -rw-r--r-- | sem_2/HLIN202/TP/TP3-4/ex12/exo12.cpp | 23 | ||||
| -rw-r--r-- | sem_2/HLIN202/TP/TP3-4/ex13/exo13 | bin | 0 -> 13775 bytes | |||
| -rw-r--r-- | sem_2/HLIN202/TP/TP3-4/ex13/exo13.cpp | 137 | ||||
| -rw-r--r-- | sem_2/HLIN202/TP/TP3-4/ex6/exo6 | bin | 0 -> 13586 bytes | |||
| -rw-r--r-- | sem_2/HLIN202/TP/TP3-4/ex6/exo6.cpp | 39 | ||||
| -rw-r--r-- | sem_2/HLIN202/TP/TP3-4/ex7/exo7 | bin | 0 -> 9285 bytes | |||
| -rw-r--r-- | sem_2/HLIN202/TP/TP3-4/ex7/exo7.cpp | 34 | ||||
| -rw-r--r-- | sem_2/HLIN202/TP/TP3-4/ex8/exo8 | bin | 0 -> 9388 bytes | |||
| -rw-r--r-- | sem_2/HLIN202/TP/TP3-4/ex8/exo8.cpp | 25 | ||||
| -rw-r--r-- | sem_2/HLIN202/TP/TP3-4/ex9/exo9 | bin | 0 -> 9276 bytes | |||
| -rw-r--r-- | sem_2/HLIN202/TP/TP3-4/ex9/exo9.cpp | 29 |
16 files changed, 341 insertions, 0 deletions
diff --git a/sem_2/HLIN202/TP/TP3-4/bonus/bonus.cpp b/sem_2/HLIN202/TP/TP3-4/bonus/bonus.cpp new file mode 100644 index 0000000..8a8b6a3 --- /dev/null +++ b/sem_2/HLIN202/TP/TP3-4/bonus/bonus.cpp @@ -0,0 +1,33 @@ +#include<iostream>
+#include<math.h>
+
+void triangle (int k);
+int combo ( int, int);
+
+int main () {
+ triangle ( 20 );
+ return 0;
+
+}
+
+void triangle ( int k ) {
+ int n,p,ligne;
+ n = 0;
+ p = 0;
+ ligne = 1;
+ while ( p <= k) {
+ while ( n <=p ) {
+ for ( int i=0; i < ligne; i ++) {
+ std::cout<< combo ( n, i ) << " ";
+ }
+ std::cout<<std::endl;
+ n ++;
+ ligne ++;
+ }
+ p ++;
+}
+}
+
+int combo ( int n, int p) {
+ return (n == p || p == 0) ? 1 : combo(n-1,p) + combo ( n-1,p-1);
+}
diff --git a/sem_2/HLIN202/TP/TP3-4/bonus/prog b/sem_2/HLIN202/TP/TP3-4/bonus/prog Binary files differnew file mode 100644 index 0000000..da45351 --- /dev/null +++ b/sem_2/HLIN202/TP/TP3-4/bonus/prog diff --git a/sem_2/HLIN202/TP/TP3-4/ex11/exo11 b/sem_2/HLIN202/TP/TP3-4/ex11/exo11 Binary files differnew file mode 100644 index 0000000..50cfbdb --- /dev/null +++ b/sem_2/HLIN202/TP/TP3-4/ex11/exo11 diff --git a/sem_2/HLIN202/TP/TP3-4/ex11/exo11.cpp b/sem_2/HLIN202/TP/TP3-4/ex11/exo11.cpp new file mode 100644 index 0000000..f777ac5 --- /dev/null +++ b/sem_2/HLIN202/TP/TP3-4/ex11/exo11.cpp @@ -0,0 +1,21 @@ +#include<iostream>
+
+double piquart ( double incert) {
+ int cpt=3;
+ bool pair = false;
+ double pisurquatre=1;
+ while ( 1/(double)cpt> incert) {
+ pisurquatre = pair ? pisurquatre+1 /(double)cpt : pisurquatre-1/(double)cpt;
+ cpt+=2;
+ pair = pair ? false : true;
+ }
+ return pisurquatre;
+}
+
+int main () {
+ double precision;
+ std::cout<< " Entrez la precision ( < 1 ) a laquelle vous voulez apprecier la valeur de pi" << std::endl;
+ std::cin>>precision;
+ std::cout<< 4*piquart(precision)<<std::endl;
+ return 0;
+}
diff --git a/sem_2/HLIN202/TP/TP3-4/ex12/exo12 b/sem_2/HLIN202/TP/TP3-4/ex12/exo12 Binary files differnew file mode 100644 index 0000000..faeaf3a --- /dev/null +++ b/sem_2/HLIN202/TP/TP3-4/ex12/exo12 diff --git a/sem_2/HLIN202/TP/TP3-4/ex12/exo12.cpp b/sem_2/HLIN202/TP/TP3-4/ex12/exo12.cpp new file mode 100644 index 0000000..dca387c --- /dev/null +++ b/sem_2/HLIN202/TP/TP3-4/ex12/exo12.cpp @@ -0,0 +1,23 @@ +#include<iostream> + +int ackermann (int m, int n) { + int rslt=0; + if ( m == 0 && n>=0) { + rslt=n+1; + } + else if ( n==0 && m>0) { + rslt= ackermann(m-1,1); + } + else { + rslt= ackermann(m-1,ackermann(m,n-1)); + } + return rslt; +} + +int main () { + int n,m; + std::cout<<" Entrez deux nombre m et n, ce programme calcule la valeur de la fonction d'ackermann pour (m,n)"<<std::endl; + std::cin>>m>>n; + std::cout<<ackermann(m,n)<<std::endl; + return 0; +} diff --git a/sem_2/HLIN202/TP/TP3-4/ex13/exo13 b/sem_2/HLIN202/TP/TP3-4/ex13/exo13 Binary files differnew file mode 100644 index 0000000..fb21331 --- /dev/null +++ b/sem_2/HLIN202/TP/TP3-4/ex13/exo13 diff --git a/sem_2/HLIN202/TP/TP3-4/ex13/exo13.cpp b/sem_2/HLIN202/TP/TP3-4/ex13/exo13.cpp new file mode 100644 index 0000000..8a89e71 --- /dev/null +++ b/sem_2/HLIN202/TP/TP3-4/ex13/exo13.cpp @@ -0,0 +1,137 @@ + #include<iostream> + +int nbjourmois(int,bool); +int saisieJour(int,bool); +int saisieMois(); +int saisieAnnee(); +void affichejour(); +bool estbissextile(int); +int nbjourmois(int,bool); +int compteJours(int,int,bool); +int compteanneebissextile(int); +void codeJourAnnee(int,int,int); + +int main () { + int jour, mois, annee; + annee = saisieAnnee (); + mois= saisieMois (); + jour= saisieJour(mois, estbissextile(annee)); + codeJourAnnee(jour,mois,annee ); + return 0; +} + +int saisieJour (int mois, bool bissextile) { + int enter; + std::cout<<"Entrez le jour " << std::endl; + std::cin>>enter; + if ( enter > nbjourmois(mois, bissextile) || enter < 1) { + std::cout<< " Jour incorrect" << std::endl; + enter = saisieJour ( mois, bissextile); + } + return enter; +} + +int saisieMois () { + int enter; + std::cout<<"Entrez le mois"<<std::endl; + std::cin>>enter; + if ( enter < 1 || enter > 12 ) { + std::cout<<"Mois incorrect"<<std::endl; + enter = saisieMois (); + } + return enter; +} + +int saisieAnnee () { + int enter; + std::cout<<"Entrez l'annee"<<std::endl; + std::cin>>enter; + return enter; +} + +void affichejour ( int jour) { + switch ( jour ) { + case 0 : + std::cout<<"Lundi"<<std::endl; + break; + case 1 : + std::cout<<"Mardi"<<std::endl; + break; + case 2 : + std::cout<<"Mercredi"<<std::endl; + break; + case 3 : + std::cout<<"Jeudi"<<std::endl; + break; + case 4 : + std::cout<<"Vendredi"<<std::endl; + break; + case 5 : + std::cout<<"Samedi"<<std::endl; + break; + case 6 : + std::cout<<"Dimanche"<<std::endl; + break; + } +} + +bool estbissextile ( int n ) { + bool ret=false; + if ( n % 4 == 0 && n % 100 != 0 ) { + ret = true; + } + else if ( n % 400 == 0 ) { + ret = true; + } + return ret; +} + +int nbjourmois ( int n, bool bissextile) { + if ( n == 1 || n == 3 || n == 5 || n == 7 || n == 8 || n == 10 || n ==12 ) { + return 31; + } + else if ( n == 2) { + return bissextile ? 29 : 28; + } + else { + return 30; + } +} + +int compteJours ( int jour, int mois, bool bissextile) { + int jours = 0; + jours = jour; + for ( int i=1; i < mois; i ++){ + jours += nbjourmois(i, estbissextile(i)); + } + return jours; +} + +int compteanneebissextile ( int annee) { + int cpt=annee; + int rslt=0; + while ( cpt != 2000) { + if ( estbissextile(cpt)) { + rslt ++; + } + annee < 2000 ? cpt ++ : cpt --; + } + return rslt; +} + +void codeJourAnnee ( int jour, int mois, int annee) { + int rslt = 0; +//premier janvier 2000 : samedi affichejour(5); + if ( annee < 2000) { + rslt = (2000 - annee)*365 + compteanneebissextile(annee) - compteJours(jour, mois, estbissextile(annee));; + } + else if (annee > 2000 ) { + rslt += estbissextile(annee) ? compteJours(jour, mois, true) : compteJours(jour, mois, false); + rslt += (annee-2000)*365 + compteanneebissextile(annee)+1; + } + else { + rslt += compteJours(jour,mois, estbissextile(annee)); + } + std::cout<<"Le "<<jour << "/"<<mois<<"/"<<annee<<" est un "; + affichejour((rslt+4)%7); +} diff --git a/sem_2/HLIN202/TP/TP3-4/ex6/exo6 b/sem_2/HLIN202/TP/TP3-4/ex6/exo6 Binary files differnew file mode 100644 index 0000000..2db9099 --- /dev/null +++ b/sem_2/HLIN202/TP/TP3-4/ex6/exo6 diff --git a/sem_2/HLIN202/TP/TP3-4/ex6/exo6.cpp b/sem_2/HLIN202/TP/TP3-4/ex6/exo6.cpp new file mode 100644 index 0000000..d7e33c8 --- /dev/null +++ b/sem_2/HLIN202/TP/TP3-4/ex6/exo6.cpp @@ -0,0 +1,39 @@ +#include<iostream> + +bool estunenote ( float n ) { + return n <=20 && n>= 0 ? true : false; +} + +float moyenne ( int n) { + int cpt; + bool flag; + float moy, note; + cpt = 1; + flag = true; + moy = 0; + note = 0; + while ( flag && cpt <= n ) { + std::cout<<"Entrez la note numero " <<cpt<< std::endl; + std::cin>>note; + moy += note; + cpt ++; + flag = estunenote(note); + } + if ( flag ) { + moy = moy/ n; + } + else { + std :: cout << " La valeur entree n'est pas une note"<<std::endl; + moy=-1; + } + return moy; +} + +int main () { + int nb; + std::cout << " Entrez le nombre de notes" << std::endl; + std::cin >> nb; +// nb=moyenne(nb); + std::cout << " La moyenne est : " << moyenne(nb)<< std::endl; + return 0; +} diff --git a/sem_2/HLIN202/TP/TP3-4/ex7/exo7 b/sem_2/HLIN202/TP/TP3-4/ex7/exo7 Binary files differnew file mode 100644 index 0000000..1f9f23c --- /dev/null +++ b/sem_2/HLIN202/TP/TP3-4/ex7/exo7 diff --git a/sem_2/HLIN202/TP/TP3-4/ex7/exo7.cpp b/sem_2/HLIN202/TP/TP3-4/ex7/exo7.cpp new file mode 100644 index 0000000..b0d86be --- /dev/null +++ b/sem_2/HLIN202/TP/TP3-4/ex7/exo7.cpp @@ -0,0 +1,34 @@ +#include<iostream> +#include<math.h> + +bool nombreeligible ( int n) { + int som=0,cpt =1, act=0, puiss=0; + act = n; + while ( n > 10 ) { + n= n/10; + cpt ++; + } + for ( int i=cpt; i >= 0; i--) { + puiss = (int) pow(10,i); + som += (int)pow((act/puiss)%10,3); + } + return som==act ? true : false ; +} + +bool tripleteligible ( int a, int b, int c) { + int n = a*100 + b*10 + c; + return n == pow(a,3) + pow (b,3) + pow(c,3); +} + +void testeentier () { + for (int i = 2; i < 1000; i ++) { + if(nombreeligible(i)) { + std::cout << i << std::endl; + } + } +} + +int main () { + testeentier(); + return 0; +} diff --git a/sem_2/HLIN202/TP/TP3-4/ex8/exo8 b/sem_2/HLIN202/TP/TP3-4/ex8/exo8 Binary files differnew file mode 100644 index 0000000..5fcea62 --- /dev/null +++ b/sem_2/HLIN202/TP/TP3-4/ex8/exo8 diff --git a/sem_2/HLIN202/TP/TP3-4/ex8/exo8.cpp b/sem_2/HLIN202/TP/TP3-4/ex8/exo8.cpp new file mode 100644 index 0000000..81241a7 --- /dev/null +++ b/sem_2/HLIN202/TP/TP3-4/ex8/exo8.cpp @@ -0,0 +1,25 @@ +#include<iostream>
+
+bool estpremier ( int n) {
+ int cpt=2;
+ bool trouve= false;
+ while ( !trouve && cpt <= n/2 ) {
+ if ( n % cpt == 0) {
+ trouve = true;
+ }
+ cpt ++;
+ }
+ return !trouve;
+}
+int prochainpremier ( int n) {
+ while ( !estpremier(n)) {
+ n++;
+ }
+ return n;
+}
+int main () {
+ int n=0;
+ std::cin>>n;
+ std::cout << n << " prochain premier " << prochainpremier(n)<<std::endl;
+ return 0;
+}
diff --git a/sem_2/HLIN202/TP/TP3-4/ex9/exo9 b/sem_2/HLIN202/TP/TP3-4/ex9/exo9 Binary files differnew file mode 100644 index 0000000..490551d --- /dev/null +++ b/sem_2/HLIN202/TP/TP3-4/ex9/exo9 diff --git a/sem_2/HLIN202/TP/TP3-4/ex9/exo9.cpp b/sem_2/HLIN202/TP/TP3-4/ex9/exo9.cpp new file mode 100644 index 0000000..4d038ce --- /dev/null +++ b/sem_2/HLIN202/TP/TP3-4/ex9/exo9.cpp @@ -0,0 +1,29 @@ +#include<iostream>
+
+void arbre ( int base) {
+ if (base%2==1) {
+ int espaces = (base-1)/2;
+ int nb=1;
+ int etage = base / 2 +1;
+ for ( int i=1; i<=etage; i ++) {
+ for ( int j=1; j<=espaces; j ++) {
+ std::cout<<" ";
+ }
+
+ for (int k=1; k<=nb; k ++) {
+ std::cout<<"*";
+ }
+ std::cout<<std::endl;
+ espaces--;
+ nb += 2;
+ }
+ }
+}
+
+int main () {
+ int n=0;
+ std::cout << " Entrez le nombre d'etoiles voulues a la base"<<std::endl;
+ std::cin>>n;
+ arbre(n);
+ return 0;
+}
|
