/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
/* 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, t_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);
// Use value of new freezing temperature to convert into Centigrade.
t_c = (5*f_b/9) - 32;
/* Print new freezing temperature. */
printf("New freezing temperature in degrees C: %4.1f \n",t_c);
return 0; /* Exit program. */
}
/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
No comments:
Post a Comment