diff --git a/DEV1.1/TP16:Recursivite/tableau.c b/DEV1.1/TP16:Recursivite/tableau.c index 4cf37e5..f2ef8eb 100644 --- a/DEV1.1/TP16:Recursivite/tableau.c +++ b/DEV1.1/TP16:Recursivite/tableau.c @@ -4,17 +4,19 @@ void afficheTabRec(double tab[],int taille){ if(taille==0){ + return; } afficheTabRec(tab, taille-1); - printf("%f, ",tab[taille-1]); + printf("%.2f, ",tab[taille-1]); } int main(){ int i; - double tab[15]=malloc(sizeof(double)); + double *tab = malloc(15 * sizeof (double)); srand(time(NULL)); for (i=0;i<15;i++){ tab[i]=(rand()%1000); } afficheTabRec(tab, sizeof(tab)); + putchar('\n'); return 0; } \ No newline at end of file diff --git a/DEV1.1/TP16:Recursivite/triangle.c b/DEV1.1/TP16:Recursivite/triangle.c new file mode 100644 index 0000000..ed64dd0 --- /dev/null +++ b/DEV1.1/TP16:Recursivite/triangle.c @@ -0,0 +1,27 @@ +#include +#include +#include +#include + +void TriangleSlerpinski(int n,int x,int y,int xx,int yy,int xxx,int yyy){ + if (n==0){ + DessinerSegment(x,y,xx,yy); + DessinerSegment(xx,yy,xxx,yyy); + DessinerSegment(xxx,yyy,x,y); + return; + } TriangleSlerpinski(n-1,x,y,xx+((xxx-xx)/4),(yy-((yy-y)/2)),xxx-((xxx-xx)/4),(yyy-((yy-y)/2))); + TriangleSlerpinski(n-1,xx+((xxx-xx)/4),(yy-((yy-y)/2)),xx,yy,xx+((xxx-xx)/2),yyy); + TriangleSlerpinski(n-1,xxx-((xxx-xx)/4),(yyy-((yy-y)/2)),xx+((xxx-xx)/2),yyy,xxx,yyy); +} + +int main(int argc, char const *argv[]) +{ + int n; + n=strtol(argv[1],NULL,10); + InitialiserGraphique(); + CreerFenetre(0,0,1000,1000); + TriangleSlerpinski(n,500,0,0,950,1000,950); + Touche(); + FermerGraphique(); + return 0; +} \ No newline at end of file