commit 35f39a0a8222fe2ef41a7e870c8d5b0f30aef523 Author: dubreuil Date: Wed Oct 15 16:42:13 2025 +0200 ajout controle diff --git a/Exercice1.c b/Exercice1.c new file mode 100644 index 0000000..5176f4d --- /dev/null +++ b/Exercice1.c @@ -0,0 +1,56 @@ +#include +#include +#include + + +int racineCarree(int n){ + if(n < 0){ + return -1; + } + + for(int i = 0; i <= n; i++){ + if((i*i) == n){ + return i; + } + } + return -1; +} + +void racineCarreeTab(int tab[], int taille){ + for(int i = 0; i < taille; i++){ + tab[i] = racineCarree(tab[i]); + } +} + + + + +int main(void) { + int Ex1T1[] = {9, 25, 4}; + int Ex1T2[] = {10, 36, 2}; + int Ex1Taille = 3; + + + srand(time(NULL)); + int Ex2Taille = 500; + int Ex2Tableau[Ex2Taille]; + for (int i = 0; i < Ex2Taille; i++) { + Ex2Tableau[i] = 1000 + rand(); + } + + printf("Exercice 1a : %d \n", racineCarree(9)); + + printf("Exercice 1b : "); + racineCarreeTab(Ex1T2, Ex1Taille); + racineCarreeTab(Ex1T1, Ex1Taille); + for(int i = 0; i < Ex1Taille; i++){ + printf("%d ", Ex1T1[i]); + } + printf("\n"); + for(int i = 0; i < Ex1Taille; i++){ + printf("%d ", Ex1T2[i]); + } + printf("\n"); + + +} \ No newline at end of file diff --git a/Exercice2.c b/Exercice2.c new file mode 100644 index 0000000..d62a6ad --- /dev/null +++ b/Exercice2.c @@ -0,0 +1,45 @@ +#include +#include +#include + + +int racineCarree(int n){ + if(n < 0){ + return -1; + } + + for(int i = 0; i <= n; i++){ + if((i*i) == n){ + return i; + } + } + return -1; +} + +void racineCarreeTab(int tab[], int taille){ + for(int i = 0; i < taille; i++){ + tab[i] = racineCarree(tab[i]); + + } +} + + + + +int main(void) { + srand(time(NULL)); + int Ex2Taille = 10000; + int Ex2Tableau[Ex2Taille]; + for (int i = 0; i < Ex2Taille; i++) { + Ex2Tableau[i] = rand() % 1000000; + } + + printf("Exercice 2 : \n"); + racineCarreeTab(Ex2Tableau, Ex2Taille); + //for(int i = 0; i < Ex2Taille; i++){ + //printf("%d ", Ex2Tableau[i]); + //} + //printf("\n"); + + +} \ No newline at end of file diff --git a/Exercice3.c b/Exercice3.c new file mode 100644 index 0000000..3a65500 --- /dev/null +++ b/Exercice3.c @@ -0,0 +1,92 @@ +#include +#include +#include + + +int racineCarree(int n){ + if(n < 0){ + return -1; + } + + for(int i = 0; i <= n; i++){ + if((i*i) == n){ + return i; + } + } + return -1; +} + + +int somme(int tab[], int taille) { + int sum = 0; + for (int i = 0; i < taille; i++) { + sum += tab[i]; + } + return sum; +} + + +int sommeRacines(int tab[], int taille) { + int sum = 0; + for (int i = 0; i < taille; i++) { + int r = racineCarree(tab[i]); + if (r != -1) { + sum += r; + } + } + return sum; +} + +void TriSpecial(int tab[], int taille, int resultat[]){ + int racinesNonEntieres = 0; + + for (int i = 0; i < taille; i++) { + if (racineCarree(tab[i]) == -1) { + racinesNonEntieres++; + } + } + + if (racinesNonEntieres % 2 == 0) { + int sum = somme(tab, taille); + for (int i = 0; i < taille; i++) { + if (i % 2 == 0) { + resultat[i] = tab[i]; + } else { + resultat[i] = sum * tab[i]; + } + } + } else { + int sRacines = sommeRacines(tab, taille); + for (int i = 0; i < taille; i++) { + if (i % 2 == 0) { + resultat[i] = racineCarree(tab[i]); + } else { + resultat[i] = sRacines * tab[i]; + } + } + } +} + + + + +int main(void) { + int Ex3T1[] = {3, 5, 25, 16}; + int Ex3T2[] = {36, 9, 100, 2, 3, 7}; + int Ex3Taille = 4; + int Ex3Taille2 = 6; + + int resultat1[Ex3Taille]; + int resultat2[Ex3Taille2]; + + TriSpecial(Ex3T1, Ex3Taille, resultat1); + for(int i = 0; i < Ex3Taille; i++){ + printf("%d ", resultat1[i]); + } + printf("\n"); + TriSpecial(Ex3T2, Ex3Taille2, resultat2); + for(int i = 0; i < Ex3Taille2; i++){ + printf("%d ", resultat2[i]); + } + printf("\n"); +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..d2d1f6f --- /dev/null +++ b/README.md @@ -0,0 +1,75 @@ +# Exercice 2 + +Pour un tableau de taille 10 000 : + +racineCarreeTab() est appelé qu'une seule fois et prend près de 0% du temps d'exécution total. +Elle est appelé par le main et fait appel à la fonction racineCarree() 10 000 fois et cette même fonction a 10.63s d'exécution. + +On peut donc conclure que pour optimiser ce temps, on devra soit limité le nombre d'appel à la fonction racineCarree() ou alors optimiser cette fonction. + +``` +index % time self children called name + 10.63 0.00 10000/10000 racineCarreeTab [2] +[1] 100.0 10.63 0.00 10000 racineCarree [1] +----------------------------------------------- + 0.00 10.63 1/1 main [3] +[2] 100.0 0.00 10.63 1 racineCarreeTab [2] + 10.63 0.00 10000/10000 racineCarree [1] +----------------------------------------------- + +[3] 100.0 0.00 10.63 main [3] + 0.00 10.63 1/1 racineCarreeTab [2] +----------------------------------------------- +``` + + + +## Complexité cyclomatique + racineCarree() +La complexité cyclomatique de racineCarree() est 5. + + racineCarreeTab() +La complexité cyclomatique de racineCarreeTab() est 2. + +## Complexité algorithmique + + racineCarree() +La complexité algorithmique de racineCarree() est + + racineCarreTab() + +La complexité algorithmique de racineCarreeTab() est + + +# Exercice 4 + + +``` +index % time self children called name + 0.00 0.00 6/19 sommeRacines [4] + 0.00 0.00 13/19 TriSpecial [2] +[1] 0.0 0.00 0.00 19 racineCarree [1] +----------------------------------------------- + 0.00 0.00 2/2 main [8] +[2] 0.0 0.00 0.00 2 TriSpecial [2] + 0.00 0.00 13/19 racineCarree [1] + 0.00 0.00 1/1 somme [3] + 0.00 0.00 1/1 sommeRacines [4] +----------------------------------------------- + 0.00 0.00 1/1 TriSpecial [2] +[3] 0.0 0.00 0.00 1 somme [3] +----------------------------------------------- + 0.00 0.00 1/1 TriSpecial [2] +[4] 0.0 0.00 0.00 1 sommeRacines [4] + 0.00 0.00 6/19 racineCarree [1] +----------------------------------------------- +``` + +## Complexité cyclomatique + + TriSpecial() +La complexité cyclomatique de TriSpepcial() est de 5. + +## Complexité algorithmique + TriSpecial() +La complexité algorithmique de TriSpecial() est \ No newline at end of file diff --git a/a.out b/a.out new file mode 100755 index 0000000..e4714c4 Binary files /dev/null and b/a.out differ diff --git a/ex2 b/ex2 new file mode 100755 index 0000000..00f4b51 Binary files /dev/null and b/ex2 differ diff --git a/ex3 b/ex3 new file mode 100755 index 0000000..3e52232 Binary files /dev/null and b/ex3 differ diff --git a/gmon.out b/gmon.out new file mode 100644 index 0000000..e727151 Binary files /dev/null and b/gmon.out differ