Advertisement
lnsee96

1-15 edited

Aug 22nd, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "stdio.h"
  2. /*Use a function to print a Fahrenheit-Celsius conversion table using the formula C=(5/9)*(F-32) with a step of 20 between values of 0 t 300 of Fahrenheit temperatures*/
  3. #define STEP 20
  4.  
  5. int Convert(int f);
  6.  
  7. main()
  8. {
  9.     int i, sum=0;
  10.     int fahrenheitValues[16]; //16 is a result of dividing the maximum value of 300 by a step of 20
  11.     for (i=0;i<16;++i)
  12.     {
  13.         if (i!=0)
  14.         {
  15.             sum=sum+STEP;
  16.         }
  17.         fahrenheitValues[i]=sum;
  18.         printf("%d\t%d\n",fahrenheitValues[i],Convert(fahrenheitValues[i]));
  19.     }
  20. }
  21.  
  22. int Convert (int f)
  23. {
  24.     int c;
  25.     c=5*(f-32)/9;
  26.     return c;
  27. }
  28. /* Matt's comments:
  29. -16 is a magic number, should have written a comment about it or written it as MAX/STEP+1
  30. -Don't call arrays array..
  31. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement