This commit is contained in:
Aissi Jude Christ
2025-10-15 16:49:17 +02:00
parent 62e244c26d
commit 1eab17d713
7 changed files with 340 additions and 0 deletions

BIN
Exercice1/a.out Executable file

Binary file not shown.

BIN
Exercice1/gmon.out Normal file

Binary file not shown.

116
Exercice1/racinecarree.c Normal file

File diff suppressed because one or more lines are too long

BIN
Exercice3/a.out Executable file

Binary file not shown.

151
Exercice3/trispecial.c Normal file
View File

@@ -0,0 +1,151 @@
#include <stdio.h>
#include <stdlib.h>
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");
}

View File

@@ -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

58
reponses.txt Normal file
View File

@@ -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]
-----------------------------------------------
<spontaneous>
[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