salinty code problem 2-4

/*  salinity problem 2  */

#include <stdio.h>
#include <math.h>
int main(void)
{
  /*  declare variables */
  double a,b,c, f_a,f_b,f_c,t_c;
printf("Enter first salinity and freezing temperature in Farehient: \n");
scanf("%lf %lf",&a,&f_a);
printf("enter second salinity and freezing temperature in farehient: \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);
t_c = (f_b -32)*.555555;
printf("new freezing termperature in degrees F: %lf \n", t_c);
return 0;
}

problem 3)
 No, if the user inputs the data in Centigrade, then there wouldn't need to be any change. if the user input the values in Fahrenheit then there would have to be a change in code to convert Fahrenheit to Centigrade

problem 4)
/*  salinity problem   */

#include <stdio.h>
#include <math.h>
int main(void)
{
  /*  declare variables */
  double a,b,c, f_a,f_b,f_c,t_c;
printf("Enter first temperature in fahrenheit and salinity: \n");
scanf("%lf %lf",&a,&f_a);
printf("enter second Temperature and salinity: \n");
scanf("%lf %lf",&c, &f_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);

printf("new salinity: %lf \n", f_b);
return 0;
}
gcc version 4.6.3
   
Enter first temperature in fahrenheit and salinity: 
 29.1
 30
enter second Temperature and salinity: 
 30.1
 20
enter new temperature:
 29.5
new salinity: 26.000000 
   

Comments

Popular posts from this blog

Day_13

Day 18 WH