TP05 Saisie console
This commit is contained in:
parent
e5aafab96e
commit
f217328b23
@ -2,7 +2,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define ANNEE 100
|
||||
#define ANNEE 2100
|
||||
|
||||
bool bissextile(int ann) {
|
||||
if (((ann % 4 == 0) && (ann % 100 != 0)) || (ann % 400 == 0)) {
|
||||
|
41
APL1.1/TP05/date_age.c
Normal file
41
APL1.1/TP05/date_age.c
Normal file
@ -0,0 +1,41 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
//Entier représentants les dates actuelles et d'anniversaires
|
||||
//au format JJ/MM/AAAA v
|
||||
int calculateAge(int dc, int mc, int yc, int db, int mb, int yb) {
|
||||
int age = yc - yb - 1; //On calcule l'age minimum que quelqu'un peut avoir
|
||||
|
||||
if (mc > mb) { //Si le mois est supérieur au mois de naissance, on rajoute 1 an
|
||||
age++;
|
||||
} else if (mc == mb && dc >= db) { //Idem si le mois est le même et le jour supérieur.
|
||||
age++;
|
||||
}
|
||||
|
||||
return age;
|
||||
}
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
int day_c, month_c, year_c, day_b, month_b, year_b;
|
||||
printf("Indiquez la date d'aujourd'hui au format JJ/MM/AAAA : ");
|
||||
int result = scanf("%d/%d/%d", &day_c, &month_c, &year_c);
|
||||
|
||||
if (result < 1) {
|
||||
printf("Format incorrect.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
result = 0;
|
||||
printf("Indiquez votre date de naissance au format JJ/MM/AAAA : ");
|
||||
result = scanf("%d/%d/%d", &day_b, &month_b, &year_b);
|
||||
|
||||
if (result < 1) {
|
||||
printf("Format incorrect.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
int age = calculateAge(day_c, month_c, year_c, day_b, month_b, year_b);
|
||||
printf("Vous avez %d ans.\n", age);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
18
APL1.1/TP05/entier.c
Normal file
18
APL1.1/TP05/entier.c
Normal file
@ -0,0 +1,18 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
int entier = 1234;
|
||||
|
||||
printf("Entrez un entier :");
|
||||
int resultat = scanf("%d", &entier);
|
||||
|
||||
if (resultat != 1) {
|
||||
printf("Mauvaise valeur entrée.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf("Vous avez tapé : %d.\n", entier);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
15
APL1.1/TP05/entier_double.c
Normal file
15
APL1.1/TP05/entier_double.c
Normal file
@ -0,0 +1,15 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
int entier1 = 1234;
|
||||
int entier2 = 5678;
|
||||
|
||||
printf("Entrez un entier :");
|
||||
scanf("%d", &entier1);
|
||||
printf("Entrez un deuxieme entier :");
|
||||
scanf("%d", &entier2);
|
||||
printf("Vous avez tapé : %d et %d\n", entier1, entier2);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
12
APL1.1/TP05/hexa_to_decimal.c
Normal file
12
APL1.1/TP05/hexa_to_decimal.c
Normal file
@ -0,0 +1,12 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
int entier;
|
||||
|
||||
printf("Entrez votre valeur hexadécimale :");
|
||||
scanf("%x", &entier);
|
||||
printf("Votre valeur '0x%X' en base 16 vaut %d en base 10.\n", entier, entier);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user