summaryrefslogtreecommitdiff
path: root/sem_2/HLIN202/TP/TP3-4
diff options
context:
space:
mode:
authorGaspard Coulet <gaspard.coulet@mines-ales.org>2021-04-28 23:05:53 +0200
committerGaspard Coulet <gaspard.coulet@mines-ales.org>2021-04-28 23:05:53 +0200
commit9fe033ea88c2f705ec18c232873d056e0c229d72 (patch)
tree0647dc8c51610c7336c88c04de2068ea14b21e17 /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.cpp33
-rw-r--r--sem_2/HLIN202/TP/TP3-4/bonus/progbin0 -> 9263 bytes
-rw-r--r--sem_2/HLIN202/TP/TP3-4/ex11/exo11bin0 -> 9336 bytes
-rw-r--r--sem_2/HLIN202/TP/TP3-4/ex11/exo11.cpp21
-rw-r--r--sem_2/HLIN202/TP/TP3-4/ex12/exo12bin0 -> 9342 bytes
-rw-r--r--sem_2/HLIN202/TP/TP3-4/ex12/exo12.cpp23
-rw-r--r--sem_2/HLIN202/TP/TP3-4/ex13/exo13bin0 -> 13775 bytes
-rw-r--r--sem_2/HLIN202/TP/TP3-4/ex13/exo13.cpp137
-rw-r--r--sem_2/HLIN202/TP/TP3-4/ex6/exo6bin0 -> 13586 bytes
-rw-r--r--sem_2/HLIN202/TP/TP3-4/ex6/exo6.cpp39
-rw-r--r--sem_2/HLIN202/TP/TP3-4/ex7/exo7bin0 -> 9285 bytes
-rw-r--r--sem_2/HLIN202/TP/TP3-4/ex7/exo7.cpp34
-rw-r--r--sem_2/HLIN202/TP/TP3-4/ex8/exo8bin0 -> 9388 bytes
-rw-r--r--sem_2/HLIN202/TP/TP3-4/ex8/exo8.cpp25
-rw-r--r--sem_2/HLIN202/TP/TP3-4/ex9/exo9bin0 -> 9276 bytes
-rw-r--r--sem_2/HLIN202/TP/TP3-4/ex9/exo9.cpp29
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
new file mode 100644
index 0000000..da45351
--- /dev/null
+++ b/sem_2/HLIN202/TP/TP3-4/bonus/prog
Binary files differ
diff --git a/sem_2/HLIN202/TP/TP3-4/ex11/exo11 b/sem_2/HLIN202/TP/TP3-4/ex11/exo11
new file mode 100644
index 0000000..50cfbdb
--- /dev/null
+++ b/sem_2/HLIN202/TP/TP3-4/ex11/exo11
Binary files differ
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
new file mode 100644
index 0000000..faeaf3a
--- /dev/null
+++ b/sem_2/HLIN202/TP/TP3-4/ex12/exo12
Binary files differ
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
new file mode 100644
index 0000000..fb21331
--- /dev/null
+++ b/sem_2/HLIN202/TP/TP3-4/ex13/exo13
Binary files differ
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
new file mode 100644
index 0000000..2db9099
--- /dev/null
+++ b/sem_2/HLIN202/TP/TP3-4/ex6/exo6
Binary files differ
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
new file mode 100644
index 0000000..1f9f23c
--- /dev/null
+++ b/sem_2/HLIN202/TP/TP3-4/ex7/exo7
Binary files differ
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
new file mode 100644
index 0000000..5fcea62
--- /dev/null
+++ b/sem_2/HLIN202/TP/TP3-4/ex8/exo8
Binary files differ
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
new file mode 100644
index 0000000..490551d
--- /dev/null
+++ b/sem_2/HLIN202/TP/TP3-4/ex9/exo9
Binary files differ
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;
+}