Programming Fundamentals/Loops/C: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
Creating |
(No difference)
|
Revision as of 01:40, 8 February 2017
loops.c
// This program displays a temperature conversion table showing Fahrenheit
// temperatures from 0 to 100, in increments of 10, and the corresponding
// Celsius temperatures using While, For, and Do loops.
#include "stdio.h"
void while_loop();
void for_loop();
void do_loop();
int main(void)
{
while_loop();
for_loop();
do_loop();
return 0;
}
void while_loop()
{
double f;
double c;
printf("F° C°\n");
f = 0;
while (f <= 100)
{
c = (f - 32) * 5 / 9;
printf("%f = %f\n", f, c);
f += 10;
}
}
void for_loop()
{
double f;
double c;
printf("F° C°\n");
for(f = 0; f <= 100; f += 10)
{
c = (f - 32) * 5 / 9;
printf("%f = %f\n", f, c);
}
}
void do_loop()
{
double f;
double c;
printf("F° C°\n");
f = 0;
do
{
c = (f - 32) * 5 / 9;
printf("%f = %f\n", f, c);
f += 10;
} while (f <= 100);
}
Try It
Copy