Commit b4fe7a2067d2bbd22b51219e933dc7b2e8f00416
0 parents
Ensemble des TP de C au 12/01/2018
Showing
16 changed files
with
398 additions
and
0 deletions
Show diff stats
No preview for this file type
1 | +++ a/Code3TP1.c | ||
@@ -0,0 +1,64 @@ | @@ -0,0 +1,64 @@ | ||
1 | +#include <stdio.h> | ||
2 | + | ||
3 | +float somme(float reel1, float reel2) { | ||
4 | + float sum2; | ||
5 | + sum2 = reel1 + reel2; | ||
6 | + return(sum2); | ||
7 | +} | ||
8 | + | ||
9 | +void MinMax(float a, float b, float c, float *min, float *max) { | ||
10 | + *min = a; | ||
11 | + *max = a; | ||
12 | + if(b>=a && b>=c){ | ||
13 | + *max = b;} | ||
14 | + else{ | ||
15 | + if(c>=a && c>=b){ | ||
16 | + *max = c;}} | ||
17 | + if(b<=a && b<=c){ | ||
18 | + *min = b;} | ||
19 | + else{ | ||
20 | + if(c<=a && c<=b){ | ||
21 | + *min = c;}} | ||
22 | +} | ||
23 | + | ||
24 | +void TraitementSuite(float *min, float *max, float *moy, int *existe){ | ||
25 | + float r, sum; | ||
26 | + int i; | ||
27 | + sum =0; | ||
28 | + printf("Saisir une suite de réels se terminant par 0 :\n"); | ||
29 | + scanf("%f",&r); | ||
30 | + i=0; | ||
31 | + if (r==0){ | ||
32 | + printf("Votre suite ne contient aucun réels\n"); | ||
33 | + *existe = 0; | ||
34 | + } | ||
35 | + else{ | ||
36 | + *min = r; | ||
37 | + *max = r; | ||
38 | + | ||
39 | + while(r!=0){ | ||
40 | + sum = somme(sum, r); | ||
41 | + MinMax(r, *min, *max, min, max); | ||
42 | + i=i+1; | ||
43 | + scanf("%f", &r); | ||
44 | + } | ||
45 | + *moy = sum/i; | ||
46 | + *existe = 1; | ||
47 | + } | ||
48 | +} | ||
49 | + | ||
50 | +int main(){ | ||
51 | + float min, max, moy; | ||
52 | + int existe; | ||
53 | + TraitementSuite(&min, &max, &moy, &existe); | ||
54 | + if (existe == 1){ | ||
55 | + printf("Le min de la suite est %f, son max est %f et sa moyenne est %f \n", min, max, moy); | ||
56 | + } | ||
57 | + else{ | ||
58 | + printf("Impossible de déterminer la moyenne, le min et le max \n");} | ||
59 | + return(0);} | ||
60 | + | ||
61 | + | ||
62 | + | ||
63 | + | ||
64 | + |
1 | +++ a/CodeTP1.c | ||
@@ -0,0 +1,34 @@ | @@ -0,0 +1,34 @@ | ||
1 | +#include <stdio.h> | ||
2 | + | ||
3 | +void affichage(float x,float y,float z) { | ||
4 | + printf("%f %f %f", x, y, z) ; | ||
5 | +} | ||
6 | + | ||
7 | +void lecture(float *px, float *py, float *pz) { | ||
8 | + scanf("%f %f %f", px, py, pz); | ||
9 | +} | ||
10 | + | ||
11 | +void MinMax2(float *pa, float *pb) { | ||
12 | + float temp; | ||
13 | + if (*pa > *pb) | ||
14 | + { | ||
15 | + temp = *pa; | ||
16 | + *pa = *pb; | ||
17 | + *pb = temp; | ||
18 | + } | ||
19 | +} | ||
20 | + | ||
21 | +void Tri(float *pa, float *pb, float *pc) { | ||
22 | + MinMax2(pa,pb); | ||
23 | + MinMax2(pa,pc); | ||
24 | + MinMax2(pb,pc); | ||
25 | +} | ||
26 | + | ||
27 | +int main() { | ||
28 | + float x, y, z; | ||
29 | + lecture(&x, &y, &z); | ||
30 | + Tri(&x, &y, &z); | ||
31 | + affichage(x, y, z); | ||
32 | + return 0; | ||
33 | +} | ||
34 | + |
1 | +++ a/CodeTP1Bis.c | ||
@@ -0,0 +1,62 @@ | @@ -0,0 +1,62 @@ | ||
1 | +#include <stdio.h> | ||
2 | +#include <ctype.h> | ||
3 | + | ||
4 | +int chiffre(char ch) { | ||
5 | + int rep; | ||
6 | + if (isdigit(ch)){ | ||
7 | + rep =1;} | ||
8 | + else{ | ||
9 | + rep=0; | ||
10 | + } | ||
11 | + return rep; | ||
12 | +} | ||
13 | + | ||
14 | +int minuscule(char ch) { | ||
15 | + int rep; | ||
16 | + char x, y; | ||
17 | + x = 'a'; | ||
18 | + y = 'z'; | ||
19 | + if (ch<x || ch>y){ | ||
20 | + rep =0;} | ||
21 | + else{ | ||
22 | + rep=1; | ||
23 | + } | ||
24 | + return rep; | ||
25 | +} | ||
26 | + | ||
27 | +int majuscule(char ch) { | ||
28 | + int rep; | ||
29 | + char x, y; | ||
30 | + y = 'Z'; | ||
31 | + x = 'A'; | ||
32 | + if (ch<x || ch>y){ | ||
33 | + rep =0;} | ||
34 | + else{ | ||
35 | + rep=1; | ||
36 | + } | ||
37 | + return rep; | ||
38 | +} | ||
39 | + | ||
40 | +void analysePhrase(int *pMaj, int *pMin, int *pChi, int *pCar) { | ||
41 | + char lettre; | ||
42 | + printf("Saisir une phrase se terminant par un point : "); | ||
43 | + scanf("%c", &lettre); | ||
44 | + *pMaj=0; | ||
45 | + *pMin=0; | ||
46 | + *pChi=0; | ||
47 | + *pCar=0; | ||
48 | + while (lettre != '.') { | ||
49 | + *pMaj= *pMaj + majuscule(lettre); | ||
50 | + *pMin= *pMin + minuscule(lettre); | ||
51 | + *pChi= *pChi + chiffre(lettre); | ||
52 | + *pCar= *pCar + 1; | ||
53 | + scanf("%c", &lettre); | ||
54 | + } | ||
55 | +} | ||
56 | + | ||
57 | +int main() { | ||
58 | + int Nmaj, Nmin, Nchi, Ncar; | ||
59 | + analysePhrase(&Nmaj, &Nmin, &Nchi, &Ncar); | ||
60 | + printf("Phrase de %d charactère(s), contenant %d majuscule(s), %d minuscule(s) et %d chiffre(s)", Ncar, Nmaj, Nmin, Nchi); | ||
61 | + return(0); | ||
62 | +} |
1 | +++ a/CodeTP1Ter.c | ||
@@ -0,0 +1,45 @@ | @@ -0,0 +1,45 @@ | ||
1 | +#include <stdio.h> | ||
2 | + | ||
3 | +void LireDate(int *pj,int *pm,int *pa) { | ||
4 | + printf("Saisissez une date sous la forme jj mm aaaa : "); | ||
5 | + scanf("%d%d%d", pj, pm, pa); | ||
6 | + while (*pj > 31 ||*pj < 1 || *pm > 12 || *pm < 1 || *pa < 1){ | ||
7 | + printf("La date saisie es incorrecte ! Saisissez une date sous la forme jj mm aaaa : "); | ||
8 | + scanf("%d%d%d", pj, pm, pa);} | ||
9 | +} | ||
10 | + | ||
11 | +void LireDate2(int *pj1, int *pm1, int *pa1, int *pj2, int *pm2, int *pa2) { | ||
12 | + LireDate(pj1, pm1, pa1); | ||
13 | + LireDate(pj2, pm2, pa2); | ||
14 | +} | ||
15 | + | ||
16 | +int CompareDates(int *pj1, int *pm1, int *pa1, int *pj2, int *pm2, int *pa2, int *pres){ | ||
17 | + float d1, d2; | ||
18 | + d1 = (364.25 * (*pa1-1)) + (30.35 * (*pm1-1)) + (*pj1-1); | ||
19 | + d2 = (364.25 * (*pa2-1)) + (30.35 * (*pm2-1)) + (*pj2-1); | ||
20 | + if (d1==d2) { | ||
21 | + *pres = 0; | ||
22 | + } | ||
23 | + else { | ||
24 | + if (d1 < d2){ | ||
25 | + *pres = -1; | ||
26 | + } | ||
27 | + else { | ||
28 | + *pres = 1; | ||
29 | + } | ||
30 | + } | ||
31 | + return(*pres); | ||
32 | +} | ||
33 | + | ||
34 | +int main() { | ||
35 | + int j1, m1, a1, j2, m2, a2, res; | ||
36 | + LireDate2(&j1, &m1, &a1, &j2, &m2, &a2); | ||
37 | + CompareDates(&j1, &m1, &a1, &j2, &m2, &a2, &res); | ||
38 | + printf("%d \n\n", res); | ||
39 | +} | ||
40 | + | ||
41 | + | ||
42 | + | ||
43 | + | ||
44 | + | ||
45 | + |
1 | +++ a/Soundex.c | ||
@@ -0,0 +1,78 @@ | @@ -0,0 +1,78 @@ | ||
1 | +#include <stdio.h> | ||
2 | + | ||
3 | +void LireChar(char* pc){ | ||
4 | + scanf("%c", pc); | ||
5 | +} | ||
6 | + | ||
7 | +int EstCarac(char n){ | ||
8 | + int res; | ||
9 | + if ((n >= 'A' && n <= 'Z')||(n >= 'a' && n <= 'z' )){ | ||
10 | + res = 1; | ||
11 | + } | ||
12 | + else{ | ||
13 | + res = 0; | ||
14 | + } | ||
15 | + return(res); | ||
16 | +} | ||
17 | + | ||
18 | +int EstVoyelle(char n){ | ||
19 | + int res; | ||
20 | + 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'){ | ||
21 | + res = 1; | ||
22 | + } | ||
23 | + else{ | ||
24 | + res = 0; | ||
25 | + } | ||
26 | + return(res); | ||
27 | +} | ||
28 | + | ||
29 | + | ||
30 | +int main(){ | ||
31 | + | ||
32 | + char c, stock; | ||
33 | + int j=0,resC, resV; | ||
34 | + printf("Saisissez votre nom : "); | ||
35 | + LireChar(&c); | ||
36 | + resC = EstCarac(c); | ||
37 | + | ||
38 | + if(resC == 1){ | ||
39 | + printf("Code Soundex : %c",c); | ||
40 | + j= j+1; | ||
41 | + stock = c; | ||
42 | + } | ||
43 | + | ||
44 | + else { | ||
45 | + printf("Nom incorrect !"); | ||
46 | + } | ||
47 | + | ||
48 | + | ||
49 | + while(j < 4 && resC != 0){ | ||
50 | + | ||
51 | + LireChar(&c); | ||
52 | + resC = EstCarac(c); | ||
53 | + resV = EstVoyelle(c); | ||
54 | + | ||
55 | + if(resC == 1 && resV == 0 && c != stock){ | ||
56 | + printf("%c", c); | ||
57 | + j=j+1; | ||
58 | + stock=c; | ||
59 | + } | ||
60 | + | ||
61 | + } | ||
62 | + printf("\n"); | ||
63 | + return(0); | ||
64 | +} | ||
65 | + | ||
66 | + | ||
67 | + | ||
68 | + | ||
69 | + | ||
70 | + | ||
71 | + | ||
72 | + | ||
73 | + | ||
74 | + | ||
75 | + | ||
76 | + | ||
77 | + | ||
78 | + |
1 | +++ a/TPStructures/Base |
1 | +++ a/TPStructures/Base.c | ||
@@ -0,0 +1,84 @@ | @@ -0,0 +1,84 @@ | ||
1 | +#include <stdio.h> | ||
2 | +#define N 10 | ||
3 | +#define M 20 | ||
4 | + | ||
5 | +/* Lire une date au clavier et l'afficher */ | ||
6 | + | ||
7 | +typedef struct { | ||
8 | + int jour; | ||
9 | + int mois; | ||
10 | + int annee; | ||
11 | +} Date; | ||
12 | + | ||
13 | + | ||
14 | +typedef struct { | ||
15 | + char nom[N]; | ||
16 | + char prenom[N]; | ||
17 | + char numtel[N]; | ||
18 | + Date datenaiss; | ||
19 | +} Personne; | ||
20 | + | ||
21 | +typedef struct { | ||
22 | + Personne espace[M]; | ||
23 | + int dernier; | ||
24 | +} Annuaire; | ||
25 | + | ||
26 | +void lireDate(Date *daten){ | ||
27 | + printf("Saisir le jour : "); | ||
28 | + scanf("%d", &daten -> jour); | ||
29 | + printf("Saisir le mois : "); | ||
30 | + scanf("%d", &daten -> mois); | ||
31 | + printf("Saisir l'année : "); | ||
32 | + scanf("%d", &daten -> annee); | ||
33 | +} | ||
34 | + | ||
35 | +int lirePersonne(Personne *ppers){ | ||
36 | + printf("Saisir nom : "); | ||
37 | + if(scanf("%s", ppers -> nom) != EOF){ | ||
38 | + printf("Saisir prénom : "); | ||
39 | + scanf("%s", ppers -> prenom); | ||
40 | + printf("Saisir numéro de tel : "); | ||
41 | + scanf("%s", ppers -> numtel); | ||
42 | + printf("Saisir Date de naissance : "); | ||
43 | + lireDate(&ppers -> datenaiss); | ||
44 | + return 1; | ||
45 | + } | ||
46 | + else return 0; | ||
47 | +} | ||
48 | + | ||
49 | + | ||
50 | +void AfficherDate(Date datex){ | ||
51 | + printf("Date de naissance : "); | ||
52 | + printf("%d / %d / %d \n", datex.jour, datex.mois, datex.annee); | ||
53 | +} | ||
54 | + | ||
55 | +void AffichPersonne(Personne pers){ | ||
56 | + | ||
57 | + printf("Nom : %s \n",pers.nom); | ||
58 | + printf("Prénom : %s \n",pers.prenom); | ||
59 | + printf("Numéro de téléphone : %s \n",pers.numtel); | ||
60 | + AfficherDate(pers.datenaiss); | ||
61 | +} | ||
62 | + | ||
63 | +void CreationAnnuaire(Annuaire *pannu){ | ||
64 | + int i = -1; | ||
65 | + while (lirePersonne(&(pannu -> espace[i+1]))!=0){ | ||
66 | + i = i+1; | ||
67 | + } | ||
68 | + pannu ->dernier = i; | ||
69 | +} | ||
70 | + | ||
71 | +void AfficherAnnuaire(Annuaire annu){ | ||
72 | + int i = 0; | ||
73 | + for(i=0;i<= annu.dernier ;i++){ | ||
74 | + AffichPersonne(annu.espace[i]); | ||
75 | + } | ||
76 | +} | ||
77 | + | ||
78 | +int main(){ | ||
79 | + Annuaire annu1; | ||
80 | + CreationAnnuaire(&annu1); | ||
81 | + AfficherAnnuaire(annu1); | ||
82 | + return 0; | ||
83 | +} | ||
84 | + |
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type