Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Code d'exemple - trace un triangle de Serpienski en '#'
- de taille SIZE (constante à définir).
- */
- #include <stdio.h>
- #include <stdlib.h>
- const int SIZE = 64; // DOIT être une puissance de 2.
- void drawSerp(int begRow, int begCol, int size, char serp[SIZE][SIZE]) {
- if(size == 1) // Condition limite (le cas de base, quoi)
- serp[begRow][begCol] = '#';
- else {
- // Appels récursifs pour tracer les "sous-triangles"
- drawSerp(begRow, begCol, size/2, serp);
- drawSerp(begRow+size/2, begCol, size/2, serp);
- drawSerp(begRow, begCol+size/2, size/2, serp);
- }
- }
- int main(void) {
- char serp[SIZE][SIZE];
- int row,col;
- // Initialisation à ' ' partout
- for(row=0; row < SIZE; row++)
- for(col=0; col < SIZE; col++)
- serp[row][col]=' ';
- drawSerp(0,0,SIZE, serp);
- // Affichage du triangle
- for(row=0; row < SIZE; row++) {
- for(col=0; col < SIZE; col++)
- printf("%c", serp[row][col]);
- puts("");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment