From b4fe7a2067d2bbd22b51219e933dc7b2e8f00416 Mon Sep 17 00:00:00 2001 From: acuvelie Date: Fri, 12 Jan 2018 13:48:10 +0100 Subject: [PATCH] Ensemble des TP de C au 12/01/2018 --- .testemp.c.kate-swp | Bin 0 -> 1361 bytes Code3TP1.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ CodeTP1.c | 34 ++++++++++++++++++++++++++++++++++ CodeTP1Bis.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ CodeTP1Ter.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ Soundex.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ TPStructures/Base | 0 TPStructures/Base.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ TPStructures/Structexe | Bin 0 -> 13016 bytes TPStructures/fictex.txt | 19 +++++++++++++++++++ test2 | Bin 0 -> 8888 bytes test3 | Bin 0 -> 8800 bytes test4 | Bin 0 -> 8848 bytes testSoundex | Bin 0 -> 8848 bytes testTP1 | Bin 0 -> 8816 bytes testemp.c | 12 ++++++++++++ 16 files changed, 398 insertions(+), 0 deletions(-) create mode 100644 .testemp.c.kate-swp create mode 100644 Code3TP1.c create mode 100644 CodeTP1.c create mode 100755 CodeTP1Bis.c create mode 100644 CodeTP1Ter.c create mode 100644 Soundex.c create mode 100644 TPStructures/Base create mode 100644 TPStructures/Base.c create mode 100755 TPStructures/Structexe create mode 100644 TPStructures/fictex.txt create mode 100755 test2 create mode 100755 test3 create mode 100755 test4 create mode 100755 testSoundex create mode 100755 testTP1 create mode 100644 testemp.c diff --git a/.testemp.c.kate-swp b/.testemp.c.kate-swp new file mode 100644 index 0000000..06625f3 Binary files /dev/null and b/.testemp.c.kate-swp differ diff --git a/Code3TP1.c b/Code3TP1.c new file mode 100644 index 0000000..3a82f35 --- /dev/null +++ b/Code3TP1.c @@ -0,0 +1,64 @@ +#include + +float somme(float reel1, float reel2) { + float sum2; + sum2 = reel1 + reel2; + return(sum2); +} + +void MinMax(float a, float b, float c, float *min, float *max) { + *min = a; + *max = a; + if(b>=a && b>=c){ + *max = b;} + else{ + if(c>=a && c>=b){ + *max = c;}} + if(b<=a && b<=c){ + *min = b;} + else{ + if(c<=a && c<=b){ + *min = c;}} +} + +void TraitementSuite(float *min, float *max, float *moy, int *existe){ + float r, sum; + int i; + sum =0; + printf("Saisir une suite de réels se terminant par 0 :\n"); + scanf("%f",&r); + i=0; + if (r==0){ + printf("Votre suite ne contient aucun réels\n"); + *existe = 0; + } + else{ + *min = r; + *max = r; + + while(r!=0){ + sum = somme(sum, r); + MinMax(r, *min, *max, min, max); + i=i+1; + scanf("%f", &r); + } + *moy = sum/i; + *existe = 1; + } +} + +int main(){ + float min, max, moy; + int existe; + TraitementSuite(&min, &max, &moy, &existe); + if (existe == 1){ + printf("Le min de la suite est %f, son max est %f et sa moyenne est %f \n", min, max, moy); + } + else{ + printf("Impossible de déterminer la moyenne, le min et le max \n");} + return(0);} + + + + + diff --git a/CodeTP1.c b/CodeTP1.c new file mode 100644 index 0000000..23d7156 --- /dev/null +++ b/CodeTP1.c @@ -0,0 +1,34 @@ +#include + +void affichage(float x,float y,float z) { + printf("%f %f %f", x, y, z) ; +} + +void lecture(float *px, float *py, float *pz) { + scanf("%f %f %f", px, py, pz); +} + +void MinMax2(float *pa, float *pb) { + float temp; + if (*pa > *pb) + { + temp = *pa; + *pa = *pb; + *pb = temp; + } +} + +void Tri(float *pa, float *pb, float *pc) { + MinMax2(pa,pb); + MinMax2(pa,pc); + MinMax2(pb,pc); +} + +int main() { + float x, y, z; + lecture(&x, &y, &z); + Tri(&x, &y, &z); + affichage(x, y, z); + return 0; +} + diff --git a/CodeTP1Bis.c b/CodeTP1Bis.c new file mode 100755 index 0000000..fd23ddb --- /dev/null +++ b/CodeTP1Bis.c @@ -0,0 +1,62 @@ +#include +#include + +int chiffre(char ch) { + int rep; + if (isdigit(ch)){ + rep =1;} + else{ + rep=0; + } + return rep; +} + +int minuscule(char ch) { + int rep; + char x, y; + x = 'a'; + y = 'z'; + if (chy){ + rep =0;} + else{ + rep=1; + } + return rep; +} + +int majuscule(char ch) { + int rep; + char x, y; + y = 'Z'; + x = 'A'; + if (chy){ + rep =0;} + else{ + rep=1; + } + return rep; +} + +void analysePhrase(int *pMaj, int *pMin, int *pChi, int *pCar) { + char lettre; + printf("Saisir une phrase se terminant par un point : "); + scanf("%c", &lettre); + *pMaj=0; + *pMin=0; + *pChi=0; + *pCar=0; + while (lettre != '.') { + *pMaj= *pMaj + majuscule(lettre); + *pMin= *pMin + minuscule(lettre); + *pChi= *pChi + chiffre(lettre); + *pCar= *pCar + 1; + scanf("%c", &lettre); + } +} + +int main() { + int Nmaj, Nmin, Nchi, Ncar; + analysePhrase(&Nmaj, &Nmin, &Nchi, &Ncar); + printf("Phrase de %d charactère(s), contenant %d majuscule(s), %d minuscule(s) et %d chiffre(s)", Ncar, Nmaj, Nmin, Nchi); + return(0); +} diff --git a/CodeTP1Ter.c b/CodeTP1Ter.c new file mode 100644 index 0000000..d235fbd --- /dev/null +++ b/CodeTP1Ter.c @@ -0,0 +1,45 @@ +#include + +void LireDate(int *pj,int *pm,int *pa) { + printf("Saisissez une date sous la forme jj mm aaaa : "); + scanf("%d%d%d", pj, pm, pa); + while (*pj > 31 ||*pj < 1 || *pm > 12 || *pm < 1 || *pa < 1){ + printf("La date saisie es incorrecte ! Saisissez une date sous la forme jj mm aaaa : "); + scanf("%d%d%d", pj, pm, pa);} +} + +void LireDate2(int *pj1, int *pm1, int *pa1, int *pj2, int *pm2, int *pa2) { + LireDate(pj1, pm1, pa1); + LireDate(pj2, pm2, pa2); +} + +int CompareDates(int *pj1, int *pm1, int *pa1, int *pj2, int *pm2, int *pa2, int *pres){ + float d1, d2; + d1 = (364.25 * (*pa1-1)) + (30.35 * (*pm1-1)) + (*pj1-1); + d2 = (364.25 * (*pa2-1)) + (30.35 * (*pm2-1)) + (*pj2-1); + if (d1==d2) { + *pres = 0; + } + else { + if (d1 < d2){ + *pres = -1; + } + else { + *pres = 1; + } + } + return(*pres); +} + +int main() { + int j1, m1, a1, j2, m2, a2, res; + LireDate2(&j1, &m1, &a1, &j2, &m2, &a2); + CompareDates(&j1, &m1, &a1, &j2, &m2, &a2, &res); + printf("%d \n\n", res); +} + + + + + + diff --git a/Soundex.c b/Soundex.c new file mode 100644 index 0000000..219078b --- /dev/null +++ b/Soundex.c @@ -0,0 +1,78 @@ +#include + +void LireChar(char* pc){ + scanf("%c", pc); +} + +int EstCarac(char n){ + int res; + if ((n >= 'A' && n <= 'Z')||(n >= 'a' && n <= 'z' )){ + res = 1; + } + else{ + res = 0; + } + return(res); +} + +int EstVoyelle(char n){ + int res; + if (n == 'a' || n == 'e' || n == 'i' || n == 'o' || n == 'u' || n == 'y' || n == 'A' || n == 'E' || n == 'I' || n == 'O' ||n == 'U' ||n == 'Y'){ + res = 1; + } + else{ + res = 0; + } + return(res); +} + + +int main(){ + + char c, stock; + int j=0,resC, resV; + printf("Saisissez votre nom : "); + LireChar(&c); + resC = EstCarac(c); + + if(resC == 1){ + printf("Code Soundex : %c",c); + j= j+1; + stock = c; + } + + else { + printf("Nom incorrect !"); + } + + + while(j < 4 && resC != 0){ + + LireChar(&c); + resC = EstCarac(c); + resV = EstVoyelle(c); + + if(resC == 1 && resV == 0 && c != stock){ + printf("%c", c); + j=j+1; + stock=c; + } + + } + printf("\n"); + return(0); +} + + + + + + + + + + + + + + diff --git a/TPStructures/Base b/TPStructures/Base new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/TPStructures/Base diff --git a/TPStructures/Base.c b/TPStructures/Base.c new file mode 100644 index 0000000..bb96566 --- /dev/null +++ b/TPStructures/Base.c @@ -0,0 +1,84 @@ +#include +#define N 10 +#define M 20 + +/* Lire une date au clavier et l'afficher */ + +typedef struct { + int jour; + int mois; + int annee; +} Date; + + +typedef struct { + char nom[N]; + char prenom[N]; + char numtel[N]; + Date datenaiss; +} Personne; + +typedef struct { + Personne espace[M]; + int dernier; +} Annuaire; + +void lireDate(Date *daten){ + printf("Saisir le jour : "); + scanf("%d", &daten -> jour); + printf("Saisir le mois : "); + scanf("%d", &daten -> mois); + printf("Saisir l'année : "); + scanf("%d", &daten -> annee); +} + +int lirePersonne(Personne *ppers){ + printf("Saisir nom : "); + if(scanf("%s", ppers -> nom) != EOF){ + printf("Saisir prénom : "); + scanf("%s", ppers -> prenom); + printf("Saisir numéro de tel : "); + scanf("%s", ppers -> numtel); + printf("Saisir Date de naissance : "); + lireDate(&ppers -> datenaiss); + return 1; + } + else return 0; +} + + +void AfficherDate(Date datex){ + printf("Date de naissance : "); + printf("%d / %d / %d \n", datex.jour, datex.mois, datex.annee); +} + +void AffichPersonne(Personne pers){ + + printf("Nom : %s \n",pers.nom); + printf("Prénom : %s \n",pers.prenom); + printf("Numéro de téléphone : %s \n",pers.numtel); + AfficherDate(pers.datenaiss); +} + +void CreationAnnuaire(Annuaire *pannu){ + int i = -1; + while (lirePersonne(&(pannu -> espace[i+1]))!=0){ + i = i+1; + } + pannu ->dernier = i; +} + +void AfficherAnnuaire(Annuaire annu){ + int i = 0; + for(i=0;i<= annu.dernier ;i++){ + AffichPersonne(annu.espace[i]); + } +} + +int main(){ + Annuaire annu1; + CreationAnnuaire(&annu1); + AfficherAnnuaire(annu1); + return 0; +} + diff --git a/TPStructures/Structexe b/TPStructures/Structexe new file mode 100755 index 0000000..0881050 Binary files /dev/null and b/TPStructures/Structexe differ diff --git a/TPStructures/fictex.txt b/TPStructures/fictex.txt new file mode 100644 index 0000000..db945d4 --- /dev/null +++ b/TPStructures/fictex.txt @@ -0,0 +1,19 @@ +Durand +Pierre +0320158567 +10 +12 +1980 +Machin +Aline +0347561248 +25 +10 +1999 +TrucMuche +Michel +0436128954 +03 +9 +1965 + diff --git a/test2 b/test2 new file mode 100755 index 0000000..6661704 Binary files /dev/null and b/test2 differ diff --git a/test3 b/test3 new file mode 100755 index 0000000..beb485d Binary files /dev/null and b/test3 differ diff --git a/test4 b/test4 new file mode 100755 index 0000000..05162f4 Binary files /dev/null and b/test4 differ diff --git a/testSoundex b/testSoundex new file mode 100755 index 0000000..cc956b4 Binary files /dev/null and b/testSoundex differ diff --git a/testTP1 b/testTP1 new file mode 100755 index 0000000..8c15d6d Binary files /dev/null and b/testTP1 differ diff --git a/testemp.c b/testemp.c new file mode 100644 index 0000000..ac6b0c1 --- /dev/null +++ b/testemp.c @@ -0,0 +1,12 @@ +#include + +int EstCarac(char n){ + int res; + if ((n >= 'A' && n <= 'Z')||(n >= 'a' && n <= 'z' )){ + res = 1; + } + else{ + res = 0; + } + return(res); +} -- libgit2 0.21.2