Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save remisharrock/92cf596968060b29c841e8236d00f47a to your computer and use it in GitHub Desktop.
Save remisharrock/92cf596968060b29c841e8236d00f47a to your computer and use it in GitHub Desktop.
#include <stdio.h>
#define METRES_PAR_PIED .3048
#define LIVRES_PAR_GRAMME .002205
#define FAHRENHEIT_PAR_CELSIUS 1.8
#define ZERO_CELSIUS_EN_FAHRENHEIT 32
double metresVersPieds(double metres)
{
return metres / METRES_PAR_PIED;
}
double grammesVersLivres(double grammes)
{
return grammes * LIVRES_PAR_GRAMME;
}
double celsiusVersFahrenheit(double celsius)
{
return celsius * FAHRENHEIT_PAR_CELSIUS + ZERO_CELSIUS_EN_FAHRENHEIT;
}
int main()
{
int nbConversions;
scanf("%d", &nbConversions);
for (int iConv = 0; iConv < nbConversions; iConv = iConv + 1)
{
double valeur;
char unite;
scanf("%lf %c", &valeur, &unite);
switch (unite)
{
case 'm':
printf("%lf p\n", metresVersPieds(valeur));
break;
case 'g':
printf("%lf l\n", grammesVersLivres(valeur));
break;
case 'c':
printf("%lf f\n", celsiusVersFahrenheit(valeur));
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment