This commit is contained in:
Simoes Lukas 2024-09-24 15:03:19 +02:00
parent ab52c40223
commit bda03135c6
5 changed files with 197 additions and 0 deletions

View File

@ -0,0 +1,33 @@
------- TP09 : Boucles (encore) -------
1.
# include <stdio.h>
# include <stdlib.h>
int main(void) {
int hauteur;
int temp_espaces;
int temp_etoiles;
int i;
int j;
temp_etoiles = 1;
printf("Hauteur ? ");
scanf("%d", &hauteur);
printf("\n");
temp_espaces = hauteur - 1;
for (; hauteur != 0; hauteur -= 1) {
for (i = 0; i != temp_espaces; i += 1) {
printf(" ");
}
temp_espaces -= 1;
for (j = 0; j != temp_etoiles; j += 1) {
printf("*");
}
temp_etoiles += 2;
printf("\n");
}
return EXIT_SUCCESS;
}
2.

View File

@ -0,0 +1,37 @@
------- TP09 : Boucles (encore) -------
1.
# include <stdio.h>
# include <stdlib.h>
int main(void) {
int hauteur;
int temp_espaces;
int temp_etoiles;
int i;
int j;
temp_etoiles = 1;
printf("Hauteur ? ");
scanf("%d", &hauteur);
printf("\n");
temp_espaces = hauteur - 1;
for (; hauteur != 0; hauteur -= 1) {
for (i = 0; i != temp_espaces; i += 1) {
printf(" ");
}
temp_espaces -= 1;
for (j = 0; j != temp_etoiles; j += 1) {
printf("*");
}
temp_etoiles += 2;
printf("\n");
}
return EXIT_SUCCESS;
}
--------------------------------------------
2.

39
DEV1.1/TP09/tests.c Normal file
View File

@ -0,0 +1,39 @@
# include <stdio.h>
# include <stdlib.h>
int main(void) {
int hauteur;
char choix;
int i;
int j;
printf("_______________\n t) Triangle\n c) Carré\n q) Quitter\n Votre choix ? ");
choix = getchar();
while (choix != 'q') {
printf("\n\nHauteur ? ");
scanf("%d", &hauteur);
if (choix == 't') {
for (i = 0; i != hauteur; i++) {
for (j = 0; j != i; j++) {
printf("*");
}
printf("\n");
}
}
else {
for (i = 0; i != hauteur; i++) {
printf("*");
}
printf("\n");
for (i = 0; i != (hauteur - 2); i++) {
printf("*");
for (j = 0; j != (hauteur - 2); j++) {
printf(" ");
}
printf("*\n");
}
}
printf("_______________\n t) Triangle\n c) Carré\n q) Quitter\n Votre choix ? ");
choix = getchar();
}
return EXIT_SUCCESS;
}

View File

@ -0,0 +1,62 @@
-------- TP10 : Types --------
# include <stdio.h>
# include <stdlib.h>
int main(void) {
printf("%d\n", 77);
printf("%c%c\n", '7', '7');
printf("%hd\n", 77);
printf("%u\n", 77U);
printf("%ld\n", 77L);
printf("%lu\n", 77UL);
return EXIT_SUCCESS;
}
-------------------------------
# include <stdio.h>
# include <stdlib.h>
int main(void) {
int valeur;
char texte;
printf("Entier : ");
scanf("%d", &valeur);
texte = (char) valeur;
printf("%c", texte);
return EXIT_SUCCESS;
}
Lorsque l'on passe d'un int à un char, le char prend comme valeur
le numéro du caractère ASCII correspondant à l'int converti.
-----------------------------
# include <stdio.h>
# include <stdlib.h>
int main(void) {
int lundi;
int mardi;
int mercredi;
int jeudi;
int vendredi;
printf("1er jour : ");
scanf("%d", &lundi);
getchar();
printf("\n2e jour : ");
scanf("%d", &mardi);
getchar();
printf("\n3e jour : ");
scanf("%d", &mercredi);
getchar();
printf("\n4e jour : ");
scanf("%d", &jeudi);
getchar();
printf("\n5e jour : ");
scanf("%d", &vendredi);
printf("\nMoyenne : %.2f", (double) (lundi + mardi + mercredi + jeudi + vendredi) / 5);
return EXIT_SUCCESS;
}

26
DEV1.1/TP10/tests.c Normal file
View File

@ -0,0 +1,26 @@
# include <stdio.h>
# include <stdlib.h>
int main(void) {
int lundi;
int mardi;
int mercredi;
int jeudi;
int vendredi;
printf("1er jour : ");
scanf("%d", &lundi);
getchar();
printf("\n2e jour : ");
scanf("%d", &mardi);
getchar();
printf("\n3e jour : ");
scanf("%d", &mercredi);
getchar();
printf("\n4e jour : ");
scanf("%d", &jeudi);
getchar();
printf("\n5e jour : ");
scanf("%d", &vendredi);
printf("\nMoyenne : %.2f", (double) (lundi + mardi + mercredi + jeudi + vendredi) / 5);
return EXIT_SUCCESS;
}