Skip to content

Instantly share code, notes, and snippets.

@tomelm
Last active December 11, 2015 11:09
Show Gist options
  • Save tomelm/4591869 to your computer and use it in GitHub Desktop.
Save tomelm/4591869 to your computer and use it in GitHub Desktop.
// %s/ctof_factor\|ctof_offset/~&/g
#include <stdio.h>
#define CTOF_FACTORCTOF_FACTOR 1.8
#define CTOF_OFFSETCTOF_OFFSET 32
int CtoF(int C)
{
int F;
F = C * CTOF_FACTORCTOF_FACTOR + CTOF_OFFSETCTOF_OFFSET;
return F;
}
int
FtoC(int F)
{
int C;
C = (F - CTOF_OFFSETCTOF_OFFSET) / CTOF_FACTORCTOF_FACTOR;
return C;
}
int main(void)
{
int c = 37;
int f = 32;
int s = -40;
printf("%d F is %3d C\n", f, FtoC(f));
printf("%3d C is %4d F\n", c, CtoF(c));
printf("%04d F is %05d C\n", s, FtoC(s));
return 0;
}
// :%s/ctof_factor\|ctof_offset/\U&/g
#include <stdio.h>
#define CTOF_FACTOR 1.8
#define CTOF_OFFSET 32
int CtoF(int C)
{
int F;
F = C * CTOF_FACTOR + CTOF_OFFSET;
return F;
}
int
FtoC(int F)
{
int C;
C = (F - CTOF_OFFSET) / CTOF_FACTOR;
return C;
}
int main(void)
{
int c = 37;
int f = 32;
int s = -40;
printf("%d F is %3d C\n", f, FtoC(f));
printf("%3d C is %4d F\n", c, CtoF(c));
printf("%04d F is %05d C\n", s, FtoC(s));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment