TP09 Types
This commit is contained in:
parent
abbd939ddc
commit
7dc07d2e56
32
APL1.1/TP09/affluence.c
Normal file
32
APL1.1/TP09/affluence.c
Normal file
@ -0,0 +1,32 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#include<string.h>
|
||||
|
||||
char* getDay(int i) {
|
||||
if (i == 0) return "lundi";
|
||||
else if (i == 1) return "mardi";
|
||||
else if (i == 2) return "mercredi";
|
||||
else if (i == 3) return "jeudi";
|
||||
else if (i == 4) return "vendredi";
|
||||
else if (i == 5) return "samedi";
|
||||
else if (i == 6) return "dimanche";
|
||||
else return "???";
|
||||
}
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
|
||||
int visiteurs = 0;
|
||||
|
||||
for (int i = 0; i < 7; i++) {
|
||||
printf("Visiteurs le %s : ", getDay(i));
|
||||
int x; scanf("%d", &x);
|
||||
|
||||
visiteurs += x;
|
||||
}
|
||||
|
||||
float avgVisiteur = visiteurs/7.0f;
|
||||
|
||||
printf("Il y a en moyenne %f visiteur%s par jour.\n", avgVisiteur, avgVisiteur > 1 ? "s" : "");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
10
APL1.1/TP09/comptes.c
Normal file
10
APL1.1/TP09/comptes.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
|
||||
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
22
APL1.1/TP09/debordement.c
Normal file
22
APL1.1/TP09/debordement.c
Normal file
@ -0,0 +1,22 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
|
||||
int x;
|
||||
char y;
|
||||
|
||||
printf("Veuillez saisir un entier : ");
|
||||
scanf("%d", &x);
|
||||
|
||||
y = x;
|
||||
|
||||
printf("%c\n", y);
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
/* Le programme inteprète la valeur donnée comme un caractère ASCII,
|
||||
si le caractère est négatif ou au dessus de 256, alors le programme
|
||||
renvoie soit le symbol a la position 265-x pour les valeur négatives
|
||||
soit le symbol a la position x-256 pour les valeurs > 256. */
|
||||
}
|
||||
|
35
APL1.1/TP09/monnaie.c
Normal file
35
APL1.1/TP09/monnaie.c
Normal file
@ -0,0 +1,35 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
|
||||
double somme;
|
||||
printf("Saisissez le montant de votre paiement : ");
|
||||
scanf("%lf", &somme);
|
||||
|
||||
int piece2 = 0;
|
||||
int piece20 = 0;
|
||||
int piece1 = 0;
|
||||
|
||||
while (somme >= 2) {
|
||||
somme -= 2;
|
||||
piece2++;
|
||||
}
|
||||
|
||||
while (somme >= 0.2f) {
|
||||
somme -= 0.2f;
|
||||
piece20++;
|
||||
}
|
||||
|
||||
while (somme >= 0.01f) {
|
||||
somme -= 0.01f;
|
||||
piece1++;
|
||||
}
|
||||
|
||||
printf("Il vous faudra %d pièce%s de 2€, %d pièce%s de 20¢ et %d piece%s de 1¢.\n",
|
||||
piece2, piece2 > 1 ? "s" : "", piece20, piece20 > 1 ? "s" : "",
|
||||
piece1, piece1 > 1 ? "s" : "");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
25
APL1.1/TP09/variete.c
Normal file
25
APL1.1/TP09/variete.c
Normal file
@ -0,0 +1,25 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
int a = 77;
|
||||
unsigned int b = 77U;
|
||||
|
||||
long c = 77L;
|
||||
unsigned long d = 77UL;
|
||||
|
||||
short e = 77;
|
||||
unsigned short f = 77;
|
||||
|
||||
long long g = 77LL;
|
||||
unsigned long long h = 77ULL;
|
||||
|
||||
float i = 77.0f;
|
||||
double j = 77.0;
|
||||
long double k = 77.0L;
|
||||
|
||||
printf("%d %u %ld %lu %hd %hu %lld %llu %f %lf %Lf\n", a, b, c, d, e, f, g, h, i, j, k);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user