ajout controle
This commit is contained in:
56
Exercice1.c
Normal file
56
Exercice1.c
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
|
|
||||||
|
}
|
45
Exercice2.c
Normal file
45
Exercice2.c
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
|
|
||||||
|
}
|
92
Exercice3.c
Normal file
92
Exercice3.c
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
75
README.md
Normal file
75
README.md
Normal file
@@ -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]
|
||||||
|
-----------------------------------------------
|
||||||
|
<spontaneous>
|
||||||
|
[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
|
Reference in New Issue
Block a user