finie !
This commit is contained in:
7
.vscode/settings.json
vendored
Normal file
7
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"time.h": "c",
|
||||
"stdio.h": "c",
|
||||
"stdlib.h": "c"
|
||||
}
|
||||
}
|
35
Exo1.c
Normal file
35
Exo1.c
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <stdio.h>
|
||||
|
||||
TAILLE_TAB = 10000;
|
||||
|
||||
int racineCarree(int n){
|
||||
if (n < 0){
|
||||
return -2;
|
||||
}
|
||||
for(int i = 0; i<n/2 ; i++){
|
||||
if (i*i == n){
|
||||
return i ;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int racineCarreeTab(int tab[]){
|
||||
for(int i = 0; i < TAILLE_TAB; i++){
|
||||
tab[i] = racineCarree(tab[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main (void){
|
||||
int tab[TAILLE_TAB] = {5, 9, 81};
|
||||
printf("%d \n", racineCarree(10));
|
||||
racineCarreeTab(tab);
|
||||
for (int i = 0; i<TAILLE_TAB; i++){
|
||||
printf("%d ", tab[i]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
43
Exo2.c
Normal file
43
Exo2.c
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
|
||||
int TAILLE_TAB = 10000;
|
||||
|
||||
int racineCarree(int n){
|
||||
if (n < 0){
|
||||
return -2;
|
||||
}
|
||||
for(int i = 0; i<n/2 ; i++){
|
||||
if (i*i == n){
|
||||
return i ;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int racineCarreeTab(int tab[]){
|
||||
for(int i = 0; i < TAILLE_TAB; i++){
|
||||
tab[i] = racineCarree(tab[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(void) {
|
||||
int tab[TAILLE_TAB];
|
||||
srand(time(NULL));
|
||||
|
||||
for (int i = 0; i < TAILLE_TAB; i++) {
|
||||
tab[i] = 1000000 + rand() % 1000000;
|
||||
}
|
||||
|
||||
racineCarreeTab(tab);
|
||||
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
printf("%d ", tab[i]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
76
Exo3.c
Normal file
76
Exo3.c
Normal file
@@ -0,0 +1,76 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
int TAILLE_TAB = 4;
|
||||
|
||||
int racineCarree(int n){
|
||||
if (n < 0){
|
||||
return -2;
|
||||
}
|
||||
for(int i = 0; i<n/2 ; i++){
|
||||
if (i*i == n){
|
||||
return i ;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int racineCarreeTab(int tab[]){
|
||||
for(int i = 0; i < TAILLE_TAB; i++){
|
||||
tab[i] = racineCarree(tab[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void TriSpecial(int tab[], int TAILLE_TAB) {
|
||||
int i, NbNonEntier = 0;
|
||||
long somme = 0;
|
||||
long sommeRacines = 0;
|
||||
int tmp[TAILLE_TAB];
|
||||
|
||||
|
||||
for (i = 0; i < TAILLE_TAB; i++) {
|
||||
int r = racineCarree(tab[i]);
|
||||
if (r == -1) NbNonEntier++;
|
||||
somme += tab[i];
|
||||
if (r != -2) sommeRacines += (r == -1 ? r : r);
|
||||
}
|
||||
|
||||
if (NbNonEntier % 2 == 0) {
|
||||
|
||||
for (i = 0; i < TAILLE_TAB; i++) {
|
||||
if (i % 2 == 0) tmp[i] = tab[i];
|
||||
else
|
||||
tmp[i] = somme * tab[i];
|
||||
}
|
||||
} else {
|
||||
|
||||
for (i = 0; i < TAILLE_TAB; i++) {
|
||||
if (i % 2 == 0) tmp[i] = racineCarree(tab[i]);
|
||||
else
|
||||
tmp[i] = sommeRacines * tab[i];
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < TAILLE_TAB; i++) {
|
||||
tab[i] = tmp[i];
|
||||
}
|
||||
}
|
||||
|
||||
int main (void){
|
||||
int tabtest[TAILLE_TAB];
|
||||
srand(time(NULL));
|
||||
|
||||
|
||||
for (int i = 0; i < TAILLE_TAB; i++) {
|
||||
tabtest[i] = 1000000 + rand() % 1000000;
|
||||
}
|
||||
int tab[] = {3,5,25,16} ;
|
||||
TriSpecial(tab, TAILLE_TAB);
|
||||
for (int i = 0; i<TAILLE_TAB; i++){
|
||||
printf("%d ", tab[i]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
79
Reponses.txt
Normal file
79
Reponses.txt
Normal file
@@ -0,0 +1,79 @@
|
||||
Exercice 1
|
||||
|
||||
Pour compiler le code : gcc -pg -std=c99 Exo1.c
|
||||
|
||||
Exercice 2
|
||||
pour compiler le code : gcc -pg -std=c99 Exo2.c
|
||||
|
||||
Pour profiler avec gprof on entre la commande gprof ./a.out après avoir compiler le code
|
||||
|
||||
Flat profile:
|
||||
|
||||
Each sample counts as 0.01 seconds.
|
||||
% cumulative self self total
|
||||
time seconds seconds calls s/call s/call name
|
||||
100.23 13.59 13.59 10000 0.00 0.00 racineCarree
|
||||
0.00 13.59 0.00 1 0.00 13.59 racineCarreeTab
|
||||
|
||||
Call graph (explanation follows)
|
||||
|
||||
|
||||
granularity: each sample hit covers 2 byte(s) for 0.07% of 13.59 seconds
|
||||
|
||||
index % time self children called name
|
||||
13.59 0.00 10000/10000 racineCarreeTab [2]
|
||||
[1] 100.0 13.59 0.00 10000 racineCarree [1]
|
||||
-----------------------------------------------
|
||||
0.00 13.59 1/1 main [3]
|
||||
[2] 100.0 0.00 13.59 1 racineCarreeTab [2]
|
||||
13.59 0.00 10000/10000 racineCarree [1]
|
||||
-----------------------------------------------
|
||||
<spontaneous>
|
||||
[3] 100.0 0.00 13.59 main [3]
|
||||
0.00 13.59 1/1 racineCarreeTab [2]
|
||||
-----------------------------------------------
|
||||
|
||||
complexité cyclomatique
|
||||
|
||||
racineCarree() = 5
|
||||
racineCarreeTab() = 2
|
||||
|
||||
Complexité algorithmique
|
||||
|
||||
racineCarree() = O(n)
|
||||
racineCarreeTab() = O(t*n) avec t = taille du tableau
|
||||
|
||||
Exercice 3
|
||||
|
||||
Pour compiler : gcc -pg -std=c99 Exo3.c
|
||||
|
||||
Exercice 4
|
||||
|
||||
Pour profiler avec gprof on entre la commande gprof ./a.out après avoir compiler le code
|
||||
|
||||
Flat profile:
|
||||
|
||||
Each sample counts as 0.01 seconds.
|
||||
no time accumulated
|
||||
|
||||
% cumulative self self total
|
||||
time seconds seconds calls Ts/call Ts/call name
|
||||
0.00 0.00 0.00 6 0.00 0.00 racineCarree
|
||||
0.00 0.00 0.00 1 0.00 0.00 TriSpecial
|
||||
|
||||
Call graph (explanation follows)
|
||||
|
||||
|
||||
granularity: each sample hit covers 2 byte(s) no time propagated
|
||||
|
||||
index % time self children called name
|
||||
0.00 0.00 6/6 TriSpecial [2]
|
||||
[1] 0.0 0.00 0.00 6 racineCarree [1]
|
||||
-----------------------------------------------
|
||||
0.00 0.00 1/1 main [6]
|
||||
[2] 0.0 0.00 0.00 1 TriSpecial [2]
|
||||
0.00 0.00 6/6 racineCarree [1]
|
||||
-----------------------------------------------
|
||||
|
||||
La complexité cyclomatique de TriSpecial() est de 10
|
||||
La complexité algorithmique de TriSpecial() est O(t*n) avec t la taille du tableau
|
Reference in New Issue
Block a user