25 lines
640 B
C
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;
|
||
|
}
|