HW1   day 2

1. Modify the program so that it converts the output values from inches to feet. The input would still be entered in inches. Use a single value for the output, such as 6.5 feet.
#include <stdio.h>
#include <math.h>
int main(void)
{
/* Declare variables. */
double femur, femur_ht_f, femur_ht_m, humerus, humerus_ht_f,
humerus_ht_m;
/* Get user input from the keyboard. */
printf("Enter Values in Inches. \n");
printf("Enter femur length: \n");
scanf("%lf",&femur);
printf("Enter humerus length: \n");
scanf("%lf",&humerus);
/* Compute height estimates. */
femur_ht_f = (femur*1.94 + 28.7)*0.083;
femur_ht_m = (femur*1.88 + 32)*0.083;
humerus_ht_f = (humerus*2.8 + 28.2)*0.083;
humerus_ht_m = (humerus*2.9 + 27.9)*0.083;
/* Print height estimates. */
printf("\nHeight Estimates in ft \n");
printf("Femur Female Estimate: %5.1f \n",femur_ht_f);
printf("Femur Male Estimate: %5.1f \n",femur_ht_m);
printf("Humerus Female Estimate: %5.1f \n",humerus_ht_f);
printf("Humerus Male Estimate: %5.1f \n",humerus_ht_m);
/* Exit program. */
return 0;
} 2. Modify the program so that it asks the user to enter the values in feet. The program would then need to convert the values in feet to centimeters before doing the computations. The output would also print the output heights in feet, as in 6.5 feet.
#include <stdio.h>
#include <math.h>
int main(void)
{
/* Declare variables. */
double femur,femur_cm,humerus_cm,femur_in,humerus_in , femur_ht_f, femur_ht_m, humerus, humerus_ht_f,
humerus_ht_m;
/* Get user input from the keyboard. */
printf("Enter Values in ft. \n");
printf("Enter femur length: \n");
scanf("%lf",&femur);
printf("Enter humerus length: \n");
scanf("%lf",&humerus);
/* convert ft to cm */
femur_cm = femur*30.48;femur_in= femur*12;humerus_in=femur*12;
humerus_cm = humerus*30.48;
printf("Femur in cm : %5.1f \n",femur_cm);
printf("Humerus in cm : %5.1f \n",humerus_cm);


/* Compute height estimates. */
femur_ht_f = (femur_in*1.94 + 28.7)*0.0833333;
femur_ht_m = (femur_in*1.88 + 32)*0.0833333;
humerus_ht_f = (humerus_in*2.8 + 28.2)*0.0833333;
humerus_ht_m = (humerus_in*2.9 + 27.9)*0.0833333;
/* Print height estimates. */
printf("\nHeight Estimates in ft \n");
printf("Femur Female Estimate: %5.1f \n",femur_ht_f);
printf("Femur Male Estimate: %5.1f \n",femur_ht_m);
printf("Humerus Female Estimate: %5.1f \n",humerus_ht_f);
printf("Humerus Male Estimate: %5.1f \n",humerus_ht_m);
/* Exit program. */
return 0;
}
3. Modify the program so that it reads the input values in inches and then estimates the output heights using feet and inches. (Note that you are printing two output values for each height estimate.)
#include <stdio.h>
#include <math.h>
int main(void)
{
/* Declare variables. */
double femur, femur_ht_f, femur_ht_m, humerus, humerus_ht_f,
humerus_ht_m,femur_ht_f_ft,femur_ht_m_ft,humerus_ht_f_ft,humerus_ht_m_ft;
/* Get user input from the keyboard. */
printf("Enter Values in Inches. \n");
printf("Enter femur length: \n");
scanf("%lf",&femur);
printf("Enter humerus length: \n");
scanf("%lf",&humerus);
/* Compute height estimates. */
femur_ht_f = femur*1.94 + 28.7;
femur_ht_m = femur*1.88 + 32;
humerus_ht_f = humerus*2.8 + 28.2;
humerus_ht_m = humerus*2.9 + 27.9;
femur_ht_f_ft = (femur*1.94 + 28.7)*0.0833333;
femur_ht_m_ft = (femur*1.88 + 32)*0.0833333;
humerus_ht_f_ft = (humerus*2.8 + 28.2)*0.0833333;
humerus_ht_m_ft = (humerus*2.9 + 27.9)*0.0833333;

/* Print height estimates. */
printf("\nHeight Estimates in Inches \n");
printf("Femur Female Estimate: %5.1f \n",femur_ht_f);
printf("Femur Male Estimate: %5.1f \n",femur_ht_m);
printf("Humerus Female Estimate: %5.1f \n",humerus_ht_f);
printf("Humerus Male Estimate: %5.1f \n",humerus_ht_m);
printf("\nHeight Estimates in ft \n");
printf("Femur Female Estimate: %5.1f \n",femur_ht_f_ft);
printf("Femur Male Estimate: %5.1f \n",femur_ht_m_ft);
printf("Humerus Female Estimate: %5.1f \n",humerus_ht_f_ft);
printf("Humerus Male Estimate: %5.1f \n",humerus_ht_m_ft);

/* Exit program. */
return 0;
}
4. Modify the program so that it reads the input values in feet and inches, and then estimates the output heights using feet and inches. (Note that you are reading two input values for each bone and you are printing two output values for each height estimate.)
#include <stdio.h>
#include <math.h>
int main(void)
{
/* Declare variables. */
double femur, femur_ht_f, femur_ht_m, humerus, humerus_ht_f,
humerus_ht_m,femur_ht_f_ft,femur_ht_m_ft,humerus_ht_f_ft,humerus_ht_m_ft;
/* Get user input from the keyboard. */
printf("Enter Values in Inches. \n");
printf("Enter femur length: \n");
scanf("%lf",&femur);
printf("Enter humerus length: \n");
scanf("%lf",&humerus);
printf("Enter Values ft. \n");
printf("Enter femur length: \n");
scanf("%lf",&femur);
printf("Enter humerus length: \n");
scanf("%lf",&humerus);
/* Compute height estimates. */
femur_ht_f = femur*1.94 + 28.7;
femur_ht_m = femur*1.88 + 32;
humerus_ht_f = humerus*2.8 + 28.2;
humerus_ht_m = humerus*2.9 + 27.9;
femur_ht_f_ft = (femur*1.94 + 28.7)*0.0833333;
femur_ht_m_ft = (femur*1.88 + 32)*0.0833333;
humerus_ht_f_ft = (humerus*2.8 + 28.2)*0.0833333;
humerus_ht_m_ft = (humerus*2.9 + 27.9)*0.0833333;
/* Print height estimates. */
printf("\nHeight Estimates in Inches \n");
printf("Femur Female Estimate: %5.1f \n",femur_ht_f);
printf("Femur Male Estimate: %5.1f \n",femur_ht_m);
printf("Humerus Female Estimate: %5.1f \n",humerus_ht_f);
printf("Humerus Male Estimate: %5.1f \n",humerus_ht_m);
printf("\nHeight Estimates in ft \n");
printf("Femur Female Estimate: %5.1f \n",femur_ht_f_ft);
printf("Femur Male Estimate: %5.1f \n",femur_ht_m_ft);
printf("Humerus Female Estimate: %5.1f \n",humerus_ht_f_ft);
printf("Humerus Male Estimate: %5.1f \n",humerus_ht_m_ft);
/* Exit program. */
return 0;
}
 5 Modify the program so that it reads the bone values in centimeters and outputs the height estimates in centimeters. (Recall that 1 in = 2.54 cm.)
#include <stdio.h>
#include <math.h>
int main(void)
{
/* Declare variables. */
double femur, femur_ht_f, femur_ht_m, humerus, humerus_ht_f,
humerus_ht_m,femur_in,humerus_in;
/* Get user input from the keyboard. */
printf("Enter Values in centimeters. \n");
printf("Enter femur length: \n");
scanf("%lf",&femur);
printf("Enter humerus length: \n");
scanf("%lf",&humerus);femur_in=femur/2.54,humerus_in=humerus/2.54;
/* Compute height estimates. */
femur_ht_f = (femur*1.94 + 28.7)*2.54;
femur_ht_m = (femur*1.88 + 32)*2.54;
humerus_ht_f =(humerus*2.8 + 28.2)*2.54;
humerus_ht_m = (humerus*2.9 + 27.9)*2.54;
/* Print height estimates. */
printf("\nHeight Estimates in cm \n");
printf("Femur Female Estimate: %5.1f \n",femur_ht_f);
printf("Femur Male Estimate: %5.1f \n",femur_ht_m);
printf("Humerus Female Estimate: %5.1f \n",humerus_ht_f);
printf("Humerus Male Estimate: %5.1f \n",humerus_ht_m);
/* Exit program. */
return 0;
}


Comments

Popular posts from this blog