Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@MarcAstr0
Created November 27, 2017 15:46
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 MarcAstr0/841e36c3879d03f0fead05bf3145e893 to your computer and use it in GitHub Desktop.
Save MarcAstr0/841e36c3879d03f0fead05bf3145e893 to your computer and use it in GitHub Desktop.
Simple library for converting temperatures from Celsius to Fahrenheit and vice versa.
#include "temperature.h"
#include <math.h>
float to_fahrenheit(float celsius) {
float fahrenheit;
fahrenheit = roundf( ( (celsius * (9.00f/5.00f)) + 32.00f ) * 100.00f ) / 100.00f;
return fahrenheit;
}
float to_celsius(float fahrenheit) {
float celsius;
celsius = roundf( ( (fahrenheit - 32.00f) * (5.00f/9.00f) ) * 100.00f ) / 100.00f;
return celsius;
}
#ifndef LIBTEMP_LIBRARY_H
#define LIBTEMP_LIBRARY_H
float to_fahrenheit(float);
float to_celsius(float);
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment