DEV/BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET3/conversion.c
2024-02-01 13:55:03 +01:00

25 lines
640 B
C

#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
if (argc != 3) {
fputs("Usage: ./a.out <valeur> <unité>\n",stderr);
return EXIT_FAILURE;
}
double valeur = atof(argv[1]);
char unite = argv[2][0];
if (unite == 'c' || unite == 'C') {
double pouces = valeur / 2.54;
printf("%.2fin\n", pouces);
} else if (unite == 'i' || unite == 'I') {
double centimetres = valeur * 2.54;
printf("%.2fcm\n", centimetres);
} else {
printf("Unité invalide. Utilisez 'cm' ou 'in'.\n");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}