1)
/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
/* This program uses linear interpolation to */
/* compute the freezing temperature of seawater. */
#include <stdio.h>
#include <math.h>
int main(void)
{
/* Declare variables. */
double a, f_a, b, f_b, c, f_c, f_b_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);
/* Convert to Celcius */
f_b_c = (5/9)*f_b-32;
/* Print new freezing temperature. */
printf("New freezing temperature in degrees C: %4.1f \n",f_b_c);
return 0; /* Exit program. */
}
/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
2)The original program would not have to be changed because the degrees would change
accordingly with the formula and the ppt does not have to be changed because it does
not have any temperature units.
3)
/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
/* This program uses linear interpolation to */
/* compute the freezing temperature of seawater. */
#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 salinity and freezing temperature: \n");
scanf("%lf %lf",&f_a,&a);
printf("Enter second salinity and freezing temperature: \n");
scanf("%lf %lf",&f_c,&c);
printf("Enter new temperature: \n");
scanf("%lf",&b);
// Use linear interpolation to compute new freezing temperature.
f_b = f_a + (b-a)/(c-a)*(f_c - f_a);
/* Print new freezing temperature. */
printf("New water salinity: %2.0f ppt \n",f_b);
return 0; /* Exit program. */
}
/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
No comments:
Post a Comment