Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created December 5, 2019 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/617ccc502295b1f1acd71f1dc0723c2c to your computer and use it in GitHub Desktop.
Save parzibyte/617ccc502295b1f1acd71f1dc0723c2c to your computer and use it in GitHub Desktop.
/**
* Conversión de temperatura en ANSI C. Convertir Fahrenheit a Celsius y Celsius a Fahrenheit
*
* @author parzibyte
* @see https://parzibyte.me/blog
* */
#include <stdio.h>
float fahrenheitACelsius(float fahrenheit) {
return (fahrenheit - 32) / 1.8f;
}
float celsiusAFahrenheit(float celsius) {
return (celsius * 1.8f) + 32;
}
int main(void) {
printf("30 grados C a F: %f\n", celsiusAFahrenheit(30.0f));
printf("86 grados F a C: %f\n", fahrenheitACelsius(86.0f));
float fahrenheit = 0, celsius = 0;// Aquí almacenaremos las variables del usuario
printf("Dime los grados F:\n");
scanf("%f", &fahrenheit);
float equivalencia = fahrenheitACelsius(fahrenheit);
printf("Equivalen a %f\n", equivalencia);
printf("Dime los grados C:\n");
scanf("%f", &celsius);
equivalencia = celsiusAFahrenheit(celsius);
printf("Equivalen a %f\n", equivalencia);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment