diff --git a/APL1.1/TP04/bissextile.c b/APL1.1/TP04/bissextile.c new file mode 100644 index 0000000..9c538db --- /dev/null +++ b/APL1.1/TP04/bissextile.c @@ -0,0 +1,23 @@ +#include +#include +#include + +#define ANNEE 100 + +bool bissextile(int ann) { + if (((ann % 4 == 0) && (ann % 100 != 0)) || (ann % 400 == 0)) { + return true; + } + + return false; +} + +int main(void) { + if (bissextile(ANNEE)) { + printf("L'année %d est bissextile.\n", ANNEE); + } else { + printf("L'année %d n'est pas bissextile.\n", ANNEE); + } + + return EXIT_SUCCESS; +} diff --git a/APL1.1/TP04/bissextile_no_if.c b/APL1.1/TP04/bissextile_no_if.c new file mode 100644 index 0000000..fa2727f --- /dev/null +++ b/APL1.1/TP04/bissextile_no_if.c @@ -0,0 +1,16 @@ +#include +#include + +#define ANNEE 400 + +int main(void) { + int div_100 = ANNEE % 100 == 0; + int div_4 = ANNEE % 4 == 0; + int div_400 = ANNEE % 400 == 0; + + int index = div_100 * 4 + div_4 * 2 + div_400 * 1; + + printf("Année %d bissextile : %d.\n", ANNEE, index != 4); + + return EXIT_SUCCESS; +} diff --git a/APL1.1/TP04/comparaisons.c b/APL1.1/TP04/comparaisons.c new file mode 100644 index 0000000..be69140 --- /dev/null +++ b/APL1.1/TP04/comparaisons.c @@ -0,0 +1,14 @@ +#include +#include + +int main(void) { + int a = 7; + int b = 4; + + printf("%d > %d : %d\n", a, b, a > b); + printf("%d < %d : %d\n", a, b, a < b); + printf("%d >= %d : %d\n", a, b, a >= b); + printf("%d <= %d : %d\n", a, b, a <= b); + printf("%d == %d : %d\n", a, b, a == b); + printf("%d != %d : %d\n", a, b, a != b); +} diff --git a/APL1.1/TP04/conditions.c b/APL1.1/TP04/conditions.c new file mode 100644 index 0000000..dcd05bd --- /dev/null +++ b/APL1.1/TP04/conditions.c @@ -0,0 +1,19 @@ +#include +#include + +int main(void) { + int x = 3; + if (x = 2) { + printf("x vaut 2\n"); + } else { + printf("x est different de 2\n"); + } + printf("la valeur de x est en fait %d\n", x); + if (x = 0) { + printf("x vaut 0\n"); + } else { + printf("%s", "x est different de 0\n"); + } + printf("la valeur de x est en fait %d\n", x); + return EXIT_SUCCESS; +}