Deitel & Deitel, C How to Program 6th Edition, Exercise 9.13 (Temperature Conversions)
// 9.13 (Temperature Conversions)
float fahrenheitToCelsius(int fahrenheit);
#include <stdio.h>
int main() {
int i, fahrenheit[10] = { 0, 23, 47, 70, 94, 117, 141, 164, 188, 212 }; //10 arbitrary fahrenheit values
float celsius[10];
printf("%10s%10s\n", "Fahrenheit", "Celsius"); //headings of table
for (i = 0; i < 10; i++) {
printf("%10d", fahrenheit[i]);
celsius[i] = fahrenheitToCelsius(fahrenheit[i]); // converting fahrenheit to celsius
printf("%+10.3f\n", celsius[i]); //3 precision in 10 field width with plus and minus signs active
}
printf("\n\n\n");
return 0;
}
float fahrenheitToCelsius(int fahrenheit){ //function of fahrenheit to celsius
float celsius;
celsius = (float) 5 / 9 * (fahrenheit - 32);
return celsius;
}
float fahrenheitToCelsius(int fahrenheit);
#include <stdio.h>
int main() {
int i, fahrenheit[10] = { 0, 23, 47, 70, 94, 117, 141, 164, 188, 212 }; //10 arbitrary fahrenheit values
float celsius[10];
printf("%10s%10s\n", "Fahrenheit", "Celsius"); //headings of table
for (i = 0; i < 10; i++) {
printf("%10d", fahrenheit[i]);
celsius[i] = fahrenheitToCelsius(fahrenheit[i]); // converting fahrenheit to celsius
printf("%+10.3f\n", celsius[i]); //3 precision in 10 field width with plus and minus signs active
}
printf("\n\n\n");
return 0;
}
float fahrenheitToCelsius(int fahrenheit){ //function of fahrenheit to celsius
float celsius;
celsius = (float) 5 / 9 * (fahrenheit - 32);
return celsius;
}
OUTPUT
Fahrenheit Celsius
0 -17.778
23 -5.000
47 +8.333
70 +21.111
94 +34.444
117 +47.222
141 +60.556
164 +73.333
188 +86.667
212 +100.000
Press any key to continue . . .
Comments
Post a Comment