HW 3
2. Modify the program so that it converts and prints the new temperature in degrees Centigrade. (Recall that  TF = 9/5 TC + 32  
#include <stdio.h>
#include <math.h>
int main(void)
{
/* Declare variables. */
double a, f_a, b, f_b, c,f_b_c, f_c;
/* Get user input from the keyboard. */
printf("Use ppt for salinity values. \n");
printf("Use degrees F for temperatures. \n");
printf("Enter first salinity and freezing temperature: \n");
scanf("%lf %lf",&a,&f_a);
printf("Enter second salinity and freezing temperature: \n");
scanf("%lf %lf",&c,&f_c);
printf("Enter new salinity: \n");
scanf("%lf",&b);
// Use linear interpolation to compute new freezing temperature.
f_b = f_a + (b-a)/(c-a)*(f_c - f_a); f_b_c= (f_b -32)/1.8;
/* Print new freezing temperature. */
printf("New freezing temperature in degrees c: %4.1f \n",f_b_c);
return 0; /* Exit program. */
} 3 Suppose that the data used with the program contained values with the degrees in Centigrade. Would the program need to be changed? Explain. 4 answer: no, coz the formula does not depend on the value, it just depends on first and second value.
4
#include <stdio.h>
#include <math.h>
int main(void)
{
/* Declare variables. */
double a, f_a, b, f_b, c, f_c;
/* Get user input from the keyboard. */
printf("Use ppt for salinity values. \n");
printf("Use degrees F for temperatures. \n");
printf("Enter first freezing temperature and salinity: \n");
scanf("%lf %lf",&a,&f_a);
printf("Enter second freezing temperature and salinity: \n");
scanf("%lf %lf",&c,&f_c);
printf("Enter new salinity: \n");
scanf("%lf",&f_b);
// Use linear interpolation to compute new freezing temperature.
b=a+(f_b-f_a)*((c-a)/(f_c-f_a));
/* Print new freezing temperature. */
printf("New salinity in ppt: %4.1f \n",b);
return 0; /* Exit program. */
}

Comments

Popular posts from this blog