Exercise 2-12 Output Fahrenheit - Celsius conversion table (15 minutes)
Enter two positive integers lower
and upper
( lower
≤ upper
≦ 100), a requested output range is [ lower
, upper
], and increments of 2 ° F Fahrenheit - Celsius conversion table.
Temperature conversion formula: wherein: C represents temperature in degrees Celsius, F. Represents Fahrenheit.
Input formats:
2 on a single line integers, respectively, lower
and upper
values, separated by a space.
Output formats:
The first line of output: "fahr celsius"
Then each row outputs a Fahr Fahrenheit (integer) and a Celsius Celsius (6 characters occupying width, right justified, Reserved 1 decimal).
If the range entered is not valid, the output "Invalid.".
Sample Input 1:
32 35
Output Sample 1:
fahr celsius
32 0.0
34 1.1
Sample Input 2:
40 30
Output Sample 2:
Invalid.
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int f,a,b;
double c;
scanf("%d %d",&a,&b);
if (a<=b&&b<=100){
printf("fahr celsius\n");
for(f=a;f<=b;f+=2){
c=5.0*(f-32)/9.0;
printf("%d%6.1f\n",f,c);}
}
else
printf("Invalid.");
return 0;
}