Add: Evaluation file
This commit is contained in:
67
Ex1/racineCarree.c
Normal file
67
Ex1/racineCarree.c
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Marche pas la precision pour enlver avec -1*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int racinecarre(int n){
|
||||||
|
/* int x = n/4; /* Precision pour essayer de se rapprocher*/
|
||||||
|
|
||||||
|
if (n < 0){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i = 0; i <= n; i++ ){
|
||||||
|
if (i * i == n) { /* 2 * 2 = 4 */
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
if (i * i > n) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*x = (x + ( n / x)) /2;*/
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int racineCarreeTab(int tableau[], int taille, int resultat[]) {
|
||||||
|
for (int i = 0; i < taille; i++) {
|
||||||
|
resultat[i] = racinecarre(tableau[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
int n = 10;
|
||||||
|
int ans = racinecarre(n);
|
||||||
|
printf("%d\n", ans);
|
||||||
|
|
||||||
|
int tab1[] = {9, 25, 4};
|
||||||
|
int resultat1[3];
|
||||||
|
racineCarreeTab(tab1, 3, resultat1);
|
||||||
|
printf("racineCarreeTab([9,25,4]) = %d , %d , %d ", resultat1[0], resultat1[1], resultat1[2]);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
int tab2[] = {10, 36,-1};
|
||||||
|
int resultat2[3];
|
||||||
|
racineCarreeTab(tab2, 3, resultat2);
|
||||||
|
printf("racineCarreeTab([10, 36,-1]) = %d, %d, %d ", resultat2[0], resultat2[1], resultat2[2]);
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
51
Ex2/Readme.md
Normal file
51
Ex2/Readme.md
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
gcc -g -pg racineCarree.c
|
||||||
|
./a.out
|
||||||
|
gprof ./racineCarree
|
||||||
|
|
||||||
|
# Profilling
|
||||||
|
|
||||||
|
J'ai peut etre un probleme sur ça.
|
||||||
|
## Flat profile
|
||||||
|
|
||||||
|
% cumulative self self total
|
||||||
|
time seconds seconds calls Ts/call Ts/call name
|
||||||
|
0.00 0.00 0.00 6 0.00 0.00 racinecarre
|
||||||
|
0.00 0.00 0.00 2 0.00 0.00 racineCarreeTab
|
||||||
|
|
||||||
|
## Call profile
|
||||||
|
|
||||||
|
index % time self children called name
|
||||||
|
0.00 0.00 1/6 main [6]
|
||||||
|
0.00 0.00 5/6 racineCarreeTab [2]
|
||||||
|
[1] 0.0 0.00 0.00 6 racinecarre [1]
|
||||||
|
-----------------------------------------------
|
||||||
|
0.00 0.00 1/2 main [6]
|
||||||
|
0.00 0.00 1/2 atexit [3]
|
||||||
|
[2] 0.0 0.00 0.00 2 racineCarreeTab [2]
|
||||||
|
0.00 0.00 5/6 racinecarre [1]
|
||||||
|
|
||||||
|
-----------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Complexité cyclomatique
|
||||||
|
## RacineCarree()
|
||||||
|
- Il y a 4
|
||||||
|
- On sort dans le 1er quand n < 0 (doit etre entier positif )
|
||||||
|
- Boucle for il y a un if qui verifie la condition qui est vrai i * i = entier positif qui permet la racine 5 * 5 = 25
|
||||||
|
- if qui est faux car pas egal à l'entier positif donné
|
||||||
|
- Sortie boucle for pour le resultat et return -1 si tout les cas sont faux
|
||||||
|
Complixité cyclonique de 4
|
||||||
|
|
||||||
|
## racineCarreeTab()
|
||||||
|
- Fonction recurcise qui retourne lui meme donc 1
|
||||||
|
Complixité cyclonique de 1
|
||||||
|
|
||||||
|
# Complexité algorithmique
|
||||||
|
|
||||||
|
racineCarree() => 0(1) car on choisit la cas en fonction de n entier positif , un choix parmi les if
|
||||||
|
racineCarreeTab => O(n!) fonction recursive qui appele la racineCarre
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
BIN
Ex2/gmon.out
Normal file
BIN
Ex2/gmon.out
Normal file
Binary file not shown.
57
Ex2/racineCarree.c
Normal file
57
Ex2/racineCarree.c
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int racinecarre(int n){
|
||||||
|
/* int x = n/4; /* Precision pour essayer de se rapprocher*/
|
||||||
|
|
||||||
|
if (n < 0){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i = 0; i <= n; i++ ){
|
||||||
|
if (i * i == n) { /* 2 * 2 = 4 */
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
if (i * i > n) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*x = (x + ( n / x)) /2;*/
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int racineCarreeTab(int tableau[], int taille, int resultat[]) {
|
||||||
|
for (int i = 0; i < taille; i++) {
|
||||||
|
resultat[i] = racinecarre(tableau[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
int n = 4;
|
||||||
|
int ans = racinecarre(n);
|
||||||
|
printf("%d\n", ans);
|
||||||
|
*/
|
||||||
|
|
||||||
|
int tab1[] = {1100000, 1100000, 110000};
|
||||||
|
int resultat1[3];
|
||||||
|
racineCarreeTab(tab1, 3, resultat1);
|
||||||
|
printf("racineCarreeTab([9,25,4]) = %ld/n, %ld/n , %ld/n", resultat1[0], resultat1[1], resultat1[2]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
57
Ex3/TriSpecial.c
Normal file
57
Ex3/TriSpecial.c
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
int racinecarre(int n){
|
||||||
|
/* int x = n/4; /* Precision pour essayer de se rapprocher*/
|
||||||
|
|
||||||
|
if (n < 0){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i = 0; i <= n; i++ ){
|
||||||
|
if (i * i == n) { /* 2 * 2 = 4 */
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
if (i * i > n) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* x = (x + ( n / x)) /2; */
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int TriSpecial(int tab[]){
|
||||||
|
int nbr, somme;
|
||||||
|
int quantite = racinecarre(nbr);
|
||||||
|
|
||||||
|
/* calcul quantité pas finie */
|
||||||
|
|
||||||
|
somme = 0;
|
||||||
|
if(quantite % 2 == 0){
|
||||||
|
for (int i = 0; i < nbr; i++){
|
||||||
|
nbr = i;
|
||||||
|
somme = somme + tab[i] * nbr + 1;
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
for (int i = 0; i < nbr; i++){
|
||||||
|
racinecarre(i);
|
||||||
|
int somme = somme + racinecarre(tab[i]) + i + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
/* Pas finie */
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
int tab1[4] = {3, 5, 25, 16};
|
||||||
|
TriSpecial(tab1);
|
||||||
|
|
||||||
|
printf("Tri %d, %d, %d , %d ", tab1[0], tab1[1], tab1[2], tab1[3]);
|
||||||
|
printf("\n");
|
||||||
|
}
|
Reference in New Issue
Block a user