39 lines
789 B
C
39 lines
789 B
C
|
/* Triangle des étoiles */
|
||
|
|
||
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
|
||
|
void print_triangle(int);
|
||
|
|
||
|
int main() {
|
||
|
int nb_lignes;
|
||
|
|
||
|
printf("Entrez un nombre de lignes [3-10] : ");
|
||
|
scanf("%d", &nb_lignes);
|
||
|
|
||
|
print_triangle(nb_lignes);
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
void print_triangle(int nb_lignes) {
|
||
|
int largeur_ligne, nb_etoiles, nb_espaces;
|
||
|
|
||
|
largeur_ligne = nb_lignes * 2 - 1;
|
||
|
|
||
|
for (int i = 1; i <= nb_lignes; i++) {
|
||
|
nb_etoiles = i * 2 - 1;
|
||
|
nb_espaces = largeur_ligne - nb_etoiles;
|
||
|
for (int j = 0; j < nb_espaces/2; j++) {
|
||
|
printf(" ");
|
||
|
}
|
||
|
for (int j = 0; j < nb_etoiles; j++) {
|
||
|
printf("*");
|
||
|
}
|
||
|
for (int j = 0; j < nb_espaces/2; j++) {
|
||
|
printf(" ");
|
||
|
}
|
||
|
printf("\n");
|
||
|
}
|
||
|
}
|