Created
December 5, 2019 18:56
-
-
Save parzibyte/617ccc502295b1f1acd71f1dc0723c2c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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