debut TP15
This commit is contained in:
BIN
DEV1.1/TP15/decoupage2
Executable file
BIN
DEV1.1/TP15/decoupage2
Executable file
Binary file not shown.
54
DEV1.1/TP15/decoupage2.c
Normal file
54
DEV1.1/TP15/decoupage2.c
Normal file
@@ -0,0 +1,54 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
char menu(){
|
||||
printf("t) Triangle \nc)Carré \nq)Quitter\n");
|
||||
return getchar();
|
||||
}
|
||||
|
||||
void triangle(int hauteur){
|
||||
int etage, etoiles;
|
||||
for (etage=0;etage<hauteur;etage++){
|
||||
for (etoiles=0;etoiles<=etage;etoiles++)
|
||||
printf("*");
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
void carre( int hauteur){
|
||||
int etoiles, etage, espace;
|
||||
for (etoiles=0;etoiles<hauteur;etoiles++)
|
||||
printf("* ");
|
||||
printf("\n");
|
||||
for (etage=0;etage<(hauteur-2);etage++){
|
||||
printf("* ");
|
||||
for (espace=0;espace<(hauteur-2);espace++)
|
||||
printf(" ");
|
||||
printf("* ");
|
||||
printf("\n");
|
||||
}
|
||||
for (etoiles=0;etoiles<hauteur;etoiles++)
|
||||
printf("* ");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int etage;
|
||||
char forme;
|
||||
forme=menu();
|
||||
while(forme!='q'){
|
||||
if (forme=='c') {
|
||||
printf("Donnez un entier pour le nombre d'étage : ");
|
||||
scanf("%d",&etage);
|
||||
carre(etage);
|
||||
} else if (forme=='t') {
|
||||
printf("Donnez un entier pour le nombre d'étage : ");
|
||||
scanf("%d",&etage);
|
||||
triangle(etage);
|
||||
}
|
||||
getchar();
|
||||
forme=menu();
|
||||
}
|
||||
printf("Au revoir ...\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
47
DEV1.1/TP15/miroir.c
Normal file
47
DEV1.1/TP15/miroir.c
Normal file
@@ -0,0 +1,47 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
int remplissage( int tab[10]){
|
||||
int tour,signe;
|
||||
srand(time(NULL));
|
||||
for (tour=0;tour<10;tour++){
|
||||
tab[tour]=rand()%51;
|
||||
int tab_temp[2]={tab[tour],tab[tour]*(-1)};
|
||||
signe=rand()%2;
|
||||
tab[tour]=tab_temp[signe];
|
||||
}
|
||||
}
|
||||
|
||||
int inversion(const int tab[10], int tab_inv[10]){
|
||||
int tour;
|
||||
for (tour=0;tour<10;tour++)
|
||||
tab_val[tour]=tab[(9-tour)];
|
||||
}
|
||||
|
||||
void affichage( int tab[10]){
|
||||
int tour;
|
||||
printf("+");
|
||||
for (tour=0;tour<10;tour++)
|
||||
printf("-----+");
|
||||
printf("\n");
|
||||
printf("|");
|
||||
for (tour=0;tour<10;tour++)
|
||||
printf("%4d |",tab[tour]);
|
||||
printf("\n");
|
||||
printf("+");
|
||||
for (tour=0;tour<10;tour++)
|
||||
printf("-----+");
|
||||
printf("\n");
|
||||
|
||||
int main(void) {
|
||||
int tab[10];
|
||||
remplissage(tab);
|
||||
int tab_inv[10];
|
||||
inversion(tab,tab_inv);
|
||||
affichage(tab);
|
||||
printf("\n");
|
||||
printf("\n");
|
||||
affichage(tab_inv);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user