Let us take a look at the program .
This can be easily accomplished with a for loop or a while loop:
#include
int main()
{
int a;
a = 0;
while (a <= 100)
{
printf("%4d degrees F = %4d degrees C\n",
a, (a - 32) * 5 / 9);
a = a + 10;
}
return 0;
}
If you run this program, it will produce a table of values starting at 0 degrees F and ending at 100 degrees F. The output will look like this:
0 degrees F = -17 degrees C
10 degrees F = -12 degrees C
20 degrees F = -6 degrees C
30 degrees F = -1 degrees C
40 degrees F = 4 degrees C
50 degrees F = 10 degrees C
60 degrees F = 15 degrees C
70 degrees F = 21 degrees C
80 degrees F = 26 degrees C
90 degrees F = 32 degrees C
100 degrees F = 37 degrees C
The table's values are in increments of 10 degrees. You can see that you can easily change the starting, ending or increment values of the table that the program produces.
If you wanted your values to be more accurate, you could use floating values instead of integer values:
#include
int main()
{
float a;
a = 0;
while (a <= 100)
{
printf("%6.2f degrees F = %6.2f degrees C\n",
a, (a - 32.0) * 5.0 / 9.0);
a = a + 10;
}
return 0;
}
You can see that the declaration for a has been changed to a float, and the %f symbol replaces the %d symbol in the printf statement. In addition, the %f symbol has some formatting applied to it: The value will be printed with six digits preceding the decimal point and two digits following the decimal point.
Now let's say that we wanted to modify the program so that the temperature 98.6 is inserted in the table at the proper position. That is, we want the table to increment every 10 degrees, but we also want the table to include an extra line for 98.6 degrees F because that is the normal body temperature for a human being. The following program accomplishes the goal:
#include
int main()
{
float a;
a = 0;
while (a <= 100)
{
if (a > 98.6)
{
printf("%6.2f degrees F = %6.2f degrees C\n",
98.6, (98.6 - 32.0) * 5.0 / 9.0);
}
printf("%6.2f degrees F = %6.2f degrees C\n",
a, (a - 32.0) * 5.0 / 9.0);
a = a + 10;
}
return 0;
}
Comments
of any widgets I could add to my blog that automatically
tweet my newest twitter updates. I've been looking for a plug-in
like this for quite some time and was hoping maybe you would have some experience with something like this.
Please let me know if you run into anything. I truly enjoy
reading your blog and I look forward to your new updates.
My web page: book of ra kostenlos online spielen ohne registrierung ()
But I am not aware of any widgets like that at the moment.