66 lines
1009 B
C
66 lines
1009 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
void triangle(int t) {
|
|
int i, j;
|
|
for(i=0;i<t;i++){
|
|
for(j=0;j<t;j++){
|
|
if(i>j){
|
|
printf("*");
|
|
}
|
|
else{
|
|
printf(" ");
|
|
}
|
|
}
|
|
printf("\n");
|
|
}
|
|
}
|
|
|
|
void carre(int c) {
|
|
int i, j;
|
|
for(i=0;i<c;i++){
|
|
for(j=0;j<c;j++){
|
|
if(i==0 || i == c-1){
|
|
printf("*");
|
|
}else{
|
|
if(j==0 || j==c-1){
|
|
printf("*");
|
|
}else{
|
|
printf(" ");
|
|
}
|
|
}
|
|
}
|
|
printf("\n");
|
|
}
|
|
}
|
|
|
|
char menu() {
|
|
char ch;
|
|
printf(" t) Triangle\n c) Carre\n q) Quitter\n ");
|
|
printf("Votre choix ?\n");
|
|
ch = getchar();
|
|
return ch;
|
|
}
|
|
|
|
int main(void) {
|
|
int n;
|
|
char res = menu();
|
|
while(res != 'q'){
|
|
if(res == 't' || res == 'c'){
|
|
printf("hauteur : ");
|
|
scanf("%d",&n);
|
|
if(res == 't'){
|
|
triangle(n);
|
|
}
|
|
if(res == 'c'){
|
|
carre(n);
|
|
}
|
|
}
|
|
else{
|
|
printf("Erreur! La lettre %c n'est pas reconnue\n", res);
|
|
}
|
|
res = menu();
|
|
}
|
|
printf("Au revoir....\n");
|
|
return EXIT_SUCCESS;
|
|
} |