1

A simple program to show you how to create a table of Fahrenheit and Celsius values using a for loop. You may be able to learn from this code.

/* create a table of Fahrenheit/Celcius values */

#include <stdio.h>

int main()
{
  int fahr;

  printf( "Fahr\t Celsius\n" );
  for ( fahr = 300; fahr >= 0; fahr = fahr - 10 )
  {
    printf( "%3d \t%6.1f\n", fahr, (5.0/9.0) * (fahr-32.0) );
  }

  getchar();  /* wait for key */
  return 0;
}
3
Contributors
2
Replies
9
Views
12 Years
Discussion Span
Last Post by rubberman
0

The formula Fahrenheit to Celsius is: C = (F - 32)* 5/9

#include <stdio.h>
int main()
{
  float fahrenheit,celsius;

  printf("Give temperature in fahrenheit:");
  scanf("%f",&fahrenheit);

  celsius = (fahrenheit - 32)* 5/9;


  // one decimal
  printf( "%.1f fahrenheit = %.1f celsius", fahrenheit, celsius);

  getchar();  /* wait for key */
  getchar();
  return 0;
}

Edited by happygeek: spam deleted

0

@fozis
Bumsfeld's printf() expression is also correct - (5.0/9.0) * (fahr-32.0). You can reverse the expressions and still have the same result. IE. (5.0/9.0) * (fahr-32.0) == (fahr-32.0) * (5.0/9.0). To some, this is orthogonality - the order of expression is irrelevant. Now, I wait for someone more mathematically knowlegeable to tell me how full of it I am... :-)

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.