Files
CITISE1/IUT/Info1/TD/Exercices/9.7_dessin_motifs/dessin.cpp
2026-04-08 20:11:20 +02:00

64 lines
1.1 KiB
C++

#include <iostream>
#include "dessin.h"
using namespace std;
void afficher_n_caractere(
unsigned int nombre_etoiles,
char caractere
) {
for (
unsigned int i = 0;
i < nombre_etoiles;
i++
) {
cout << caractere;
}
}
void triangle_croissant(
unsigned int taille
) {
for (
unsigned int i = 1;
i <= taille;
i++
) {
afficher_n_caractere(i, '*');
cout << endl;
}
}
void triangle_decroissant(
unsigned int taille
) {
for (
unsigned int i = taille;
i >= 1;
i--
) {
afficher_n_caractere(i, '*');
cout << endl;
}
}
void sapin(
unsigned int taille
) {
unsigned int nombre_espaces;
unsigned int nombre_etoiles = 1;
unsigned int nombre_espaces_tronc = taille - 1;
for (unsigned int i = 0; i < taille; i++) {
nombre_espaces = taille - i;
afficher_n_caractere(nombre_espaces, ' ');
afficher_n_caractere(nombre_etoiles, '*');
cout << endl;
nombre_etoiles += 2;
}
afficher_n_caractere(nombre_espaces_tronc, ' ');
cout << "|_|" << endl;
}