diff --git a/Exercice1/a.out b/Exercice1/a.out new file mode 100755 index 0000000..1b2a6dd Binary files /dev/null and b/Exercice1/a.out differ diff --git a/Exercice1/gmon.out b/Exercice1/gmon.out new file mode 100644 index 0000000..7bd851d Binary files /dev/null and b/Exercice1/gmon.out differ diff --git a/Exercice1/racinecarree.c b/Exercice1/racinecarree.c new file mode 100644 index 0000000..819d4d5 --- /dev/null +++ b/Exercice1/racinecarree.c @@ -0,0 +1,116 @@ +#include +#include + + +int racineCarree(int nombre){ + + if (nombre < 0) { + return -1; + } + + if ( nombre == 0) { + return 0; + } + + int i; + + for (i = 0; i <= nombre; i++) { + if( i * i == nombre){ + return i; + } + if ( i * i > nombre ) { + return -1; + } + } + return -1; + +} + +void racineCarreeTab(int *tab, int *resultat, int taille) { + + int i; + + for (i = 0; i < taille; i++){ + resultat[i] = racineCarree(tab[i]); + } +} + + + +void afficherTableau(int *tab, int taille) { + printf("["); + int i; + + for (i = 0; i < taille; i++) { + printf("%d", tab[i]); + + if (i < taille - 1) { + printf(", "); + } + } + printf("]\n"); +} + + +int main() { + + /* Pour la racine carrée pour un nombre*/ + + /* + printf("racineCarree(9) = %d\n", racineCarree(9)); + printf("racineCarree(10) = %d\n", racineCarree(10)); + + */ + + /* Pour la racine carrée d'un ensemble de nombres positifs*/ + + /* + int tab1[] = {9, 25, 4}; + int taille1 = 3; + int resultat1[3]; + + + /* Racine carrée d’un ensemble de nombre entier positif + printf("Entrée: "); + afficherTableau(tab1, taille1); + racineCarreeTab(tab1, resultat1, taille1); + + printf("Résultat : "); + afficherTableau(resultat1, taille1); + */ + + /* + + int tab2[] = {10,36,2}; + int taille2 = 3; + int resultat2[3]; + + printf("Entrée: "); + afficherTableau(tab2, taille2); + racineCarreeTab(tab2, resultat2, taille2); + + printf("Résultat : "); + afficherTableau(resultat2, taille2); + + return 0; + */ + + int tab2[] = {10000000000000000000000000000000000000000000,360000000000000000000000000000000000000,200000000000000000000000000000000,82370386, 29610, -1069985664, 32767, 785898610, 29610, 1818272, 0, 1818272, 0, 782370386, 29610, 0, 0, -1069985584, 32767, 785901680, 29610, 1685382484, 4, 0, 0, 1979960, 0, -1069984976, 32767, 784369984, 29610, 785645568, 29610, 0, 0, 0, 0, -1069985552, 32767, 785872957, 29610, 0, 0, 782370386, 29610, -1069985248, 32767, 785867862, 29610, 0, 0, -1069984976, 32767, 785872896, 29610, -1069985008, 32767, 0, 0, -1069984976, 32767, -1069985280, 32767, 785935300, 29610, 786105072, 29610, 785645568, 29610, 786103712, 29610, 785645568, 29610, 0, 0, 0, 0, -1577058304, -32654, -931921920, -413901394, 0, 0, 0, 0, -1572864000, -32654, -1069985344, 32767, -1069985440, 32767, 1, 3, 0, 0, 0, 0, -1069985472, 32767, 0, 0, 0, 0, 3, 0, 3, 0, 0, 0, 0, 0, 785646912, 29610, -1069983840, 32767, 785875941, 29610, 1, 29610, 786103712, 29610, 0, 0, 785874083, 29610, 1, 22574, 785645568, 29610, -1069985264, 32767, 785874083, 29610, 1, 0, 786105072, 29610, -1069985232, 32767, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1069985200, 32767, -1069985232, 32767, -1069984912, 32767, -1069985232, 32767, 2, 0, 786105072, 29610, 0, 0, 3, 0, -1069985264, 32767, 0, 0, 0, 0, 0, 32767, 786105072, 29610, 0, 0, 0, 29610, 0, 0, 0, 0, 0, 0, 0, 0, 785645568, 29610, 0, 0, 782335800, 29610, 782370386, 29610, 786103712, 29610, 0, 0, -1069984912, 32767, 1024, 0, 786103712, 29610, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 785902445, 29610, 0, 2, 785647232, 29610, 0, 0, 1842243024, 0, 782259552, 29610, 785645568, 29610, -1069984448, 32767, 785903545, 29610, 2328, 0, 782335800, 29610, 785645568, 29610, -1069984504, 32767, -1069984508, 32767, 0, 0, 0, 0, 0, 0, 0, 0, 785902445, 29610, 3, 2, 785647232, 29610, 782246840, 29610, 1038094022, 0, 782259552, 29610, 785645568, 29610, -1069984304, 32767, 785903545, 29610, 1615, 0, 782335800, 29610, 785645568, 29610, -1069984360, 32767, -1069984364, 32767, 785647024, 29610, -431209048, 22574, 785902343, 29610, -1069983992, 32767, 1842243024, 0, 3, 0, 1416958013, 0, 785859888, 29610, 786103712, 29610, -1069984176, 32767, 785903545, 29610, 3, 0, 785860824, 29610, 786103712, 29610, -1069984232, 32767, -1069984236, 32767, 0, 0, 786106576, 29610, -1069983920, 32767, 786045000, 29610, 786106000, 29610, 3, 0, 785646944, 29610, 785859728, 29610, -1069984236, 32767, -1069984008, 32767, -1069984000, 32767, 0, 0, 0, 0, 786041589, 29610, 785860824, 29610, 0, 0, 0, 0, 786046323, 29610, 0, 0, 786041589, 29610, 786106000, 29610, -1069983848, 32767, 1416958012, 0, -1069983888, 32767, 785905858, 29610, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 786105072, 29610, -1069983984, 32767, 785924214, 29610, 0, 29610, 0, 0, -1069983952, 32767, -1069983968, 32767, 0, 0, 786106000, 29610, 0, 0, -74416640, 85883941, 786105072, 29610, 1, 0, 786105072, 29610, 0, 0, -1069983904, 32767, 782508275, 29610, 144, 3, 40, 0, 0, 0, 0, 0, 0, 0, 782841048, 29610, 0, 3, -74416640, 85883941, 786105072, 29610, 1, 0, -1069983840, 32767, 782924028, 29610, 0, 0, -1, -1, 0, 0, -74416640, 85883941, 1437325202, 18317, 785949280, 29610, -1069983152, 32767, 785997433, 29610, 0, 0, 0, 0, 0, 0, 0, 0, 785635136, 29610, 786103128, 29610, 786103712, 29610, 1437311183, 18317, 786105072, 29610, 786046464, 29610, 0, 0, 0, 0, 0, 0, 0, 0, 785851032, 29610, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 783406880, 29610, 335544324, 0, 782492992, 29610, -1, -1, 0, 0, 784374464, 29610, 8904, 0, 784374560, 29610, 0, 0, -431205327, 22574, -1069983136, 32767, 782921024, 29610, -1069982960, 32767, 0, 0, 3720, 0, 2592, 0, 1, 0, -431210496, 22574, -1069983056, 32767, 0, 12779520, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 486449152, 22575, -1069983424, 32767, 782911174, 29610, -1069983296, 32767, 782914766, 29610, 2, 9175849, 4, 0, 143360, 0, 486449152, 22575, 8944, 0, 0, 0, 143360, 0, -74416640, 85883941, 8, 0, -74416640, 85883941, -1069983072, 32767, 783407269, 29610, 0, 0, 555, 0, 0, 0, 10000, 0, 0, 0, 10000, 0, 783406880, 29610, -1, -1, 0, 0, 784374464, 29610, 8904, 0, 784374560, 29610, 0}; + int taille2 = 10000; + int resultat2[10000]; + + printf("Entrée: "); + afficherTableau(tab2, taille2); + racineCarreeTab(tab2, resultat2, taille2); + + printf("Résultat : "); + afficherTableau(resultat2, taille2); + + return 0; + + +} + + + + diff --git a/Exercice3/a.out b/Exercice3/a.out new file mode 100755 index 0000000..a565c26 Binary files /dev/null and b/Exercice3/a.out differ diff --git a/Exercice3/trispecial.c b/Exercice3/trispecial.c new file mode 100644 index 0000000..dae53a5 --- /dev/null +++ b/Exercice3/trispecial.c @@ -0,0 +1,151 @@ +#include +#include + + +int racineCarree(int nombre){ + + if (nombre < 0) { + return -1; + } + + if ( nombre == 0) { + return 0; + } + + int i; + + for (i = 0; i <= nombre; i++) { + if( i * i == nombre){ + return i; + } + if ( i * i > nombre ) { + return -1; + } + } + return -1; + +} + +int racinenonentierre(int *tab, int taille) { + + int compte; + int i; + + for (i = 0; i < taille; i++) { + if (racineCarree(tab[i]) == -1) { + compte++; + } + } + + return compte; + +} + +int sommetableau(int *tab, int taille) { + + int somme = 0; + int i; + + for (i = 0; i < taille; i++){ + somme += tab[i]; + } + + return somme; + +} + +int sommeracinecarree( int *tab, int taille) { + + int somme = 0; + int i; + + for (i = 0; i < taille; i++){ + + int racine = racineCarree(tab[i]); + + if (racine != -1) { + somme += racine; + } + } + + return somme; +} + + +void TriSpecial(int *tab, int *resultat, int taille) { + + int nbRacinesNonEntieres = racinenonentierre(tab, taille); + + int estPair = (nbRacinesNonEntieres % 2 == 0); + + if (estPair) { + + int somme = sommetableau(tab, taille); + int i; + + for (i = 0; i < taille; i++) { + + if (i % 2 == 0) { + resultat[i] = tab[i]; + } else { + resultat[i] = somme * tab[i]; + } + } + } + + else { + + int sommeRacines = sommeracinecarree(tab, taille); + int i; + + for (i = 0; i < taille; i++) { + + if (i % 2 == 0) { + resultat[i] = racineCarree(tab[i]); + + } else { + resultat[i] = sommeRacines * tab[i]; + } + } + } +} + +void afficherTableau(int *tab, int taille) { + printf("["); + int i; + + for (i = 0; i < taille; i++) { + printf("%d", tab[i]); + + if (i < taille - 1) { + printf(", "); + } + } + printf("]\n"); +} + +int main() { + + + int tab1[] = {3, 5, 25, 16}; + int taille1 = 4; + int resultat1[4]; + + printf("Entrée : "); + afficherTableau(tab1, taille1); + printf("\n"); + + int nbNonEntieres1 = racinenonentierre(tab1, taille1); + + if (nbNonEntieres1 % 2 == 0) { + printf("Somme du tableau : %d\n", sommetableau(tab1, taille1)); + } else { + printf("Somme des racines : %d\n", sommeracinecarree(tab1, taille1)); + } + + TriSpecial(tab1, resultat1, taille1); + + printf("Résultat : "); + afficherTableau(resultat1, taille1); + printf("\n"); +} \ No newline at end of file diff --git a/README.md b/README.md index e69de29..0ba7ef9 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,15 @@ + +** Commandes pour exécuter les fichiers ** + +Exercice 1 : + - Pour cet exercice j'ai utilisé les commandes : + - gcc racinecaree.c / gcc -ansi -pedantic racinecaree.c / gcc -pg racinecaree.c + - ./a.out / gprof ./a.out + + +Exercice 3 : + - Pour cet exercice j'ai utilisé les commandes : + - gcc trispecial.c / gcc -ansi -pedantic trispecial.c / gcc -pg trispecial.c + - ./a.out + + diff --git a/reponses.txt b/reponses.txt new file mode 100644 index 0000000..9a7ad23 --- /dev/null +++ b/reponses.txt @@ -0,0 +1,58 @@ +AISSI JUDE-CHRIST BUT3 + +EXERCICE 2 + +PROFILING + +Après l'exécution des commandes : + - gcc -g -pg racinecarree.c + - gprof ./a.out + + +Nous avons comme résultat : + +Flat profile: +Each sample counts as 0.01 seconds. + % cumulative self self total + time seconds seconds calls ms/call ms/call name + 100.23 0.03 0.03 10000 0.00 0.00 racineCarree + 0.00 0.03 0.00 2 0.00 0.00 afficherTableau + 0.00 0.03 0.00 1 0.00 30.07 racineCarreeTab + + +granularity: each sample hit covers 2 byte(s) for 33.26% of 0.03 seconds + +index % time self children called name + 0.03 0.00 10000/10000 racineCarreeTab [2] +[1] 100.0 0.03 0.00 10000 racineCarree [1] +----------------------------------------------- + 0.00 0.03 1/1 main [3] +[2] 100.0 0.00 0.03 1 racineCarreeTab [2] + 0.03 0.00 10000/10000 racineCarree [1] +----------------------------------------------- + +[3] 100.0 0.00 0.03 main [3] + 0.00 0.03 1/1 racineCarreeTab [2] + 0.00 0.00 2/2 afficherTableau [4] +----------------------------------------------- + 0.00 0.00 2/2 main [3] +[4] 0.0 0.00 0.00 2 afficherTableau [4] +----------------------------------------------- + + +COMPLEXITÉS + +Complexité Cyclomatique : +racineCarree() = 6 +racineCarreeTab() = 2 + +Complexité Algorithmique: +racineCarree() = O(n) +racineCarreeTab() = O(t × m) + + +Exercice 4 + +Complexité cyclomatique : + +trispecial() = 6 \ No newline at end of file