#include <stdio.h>
#include <stdlib.h>
#include <graph.h>

void triangle(int x1, int y1, int x2, int y2,int x3, int y3, int n){
	if(n == 0){
		DessinerSegment(x1, y1, x2, y2);
		DessinerSegment(x2, y2, x3, y3);
		DessinerSegment(x3, y3, x1, y1);
	}else{
		triangle(x1, y1, (x2+x1)/2, y2, (x1+x3)/2, (y2+y3)/2, n-1);
		triangle((x1+x2)/2, y1, x2, y2, (x2+x3)/2, (y2+y3)/2, n-1);
		triangle((x1+x3)/2, (y1+y3)/2, (x2+x3)/2, (y2+y3)/2, x3, y3, n-1);
	}
}

int main(void)
{
	int n = 0;
	printf("Entrez un entier positif : ");
	scanf("%d", &n);
	InitialiserGraphique();
    CreerFenetre(10,10,1000,800);
    triangle(10, 790, 990, 790, 500, 10, n);
    Touche();
    FermerGraphique();
    return EXIT_SUCCESS;
}