DEV/DEV1.1/TP10/TP10_reponses.txt

62 lines
1.2 KiB
Plaintext
Raw Permalink Normal View History

2024-09-24 15:03:19 +02:00
-------- 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;
}