Developpement/23DEV1.1/TPS1/TP01/15-Fonctions/Decoupage.c

66 lines
1009 B
C
Raw Permalink Normal View History

2024-12-09 11:53:11 +01:00
#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;
}