TP04 Année Bissextile ; Conditions
This commit is contained in:
parent
3947666c85
commit
e5aafab96e
23
APL1.1/TP04/bissextile.c
Normal file
23
APL1.1/TP04/bissextile.c
Normal file
@ -0,0 +1,23 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#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;
|
||||
}
|
16
APL1.1/TP04/bissextile_no_if.c
Normal file
16
APL1.1/TP04/bissextile_no_if.c
Normal file
@ -0,0 +1,16 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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;
|
||||
}
|
14
APL1.1/TP04/comparaisons.c
Normal file
14
APL1.1/TP04/comparaisons.c
Normal file
@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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);
|
||||
}
|
19
APL1.1/TP04/conditions.c
Normal file
19
APL1.1/TP04/conditions.c
Normal file
@ -0,0 +1,19 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user