HW_2
Comments: So, for this program I never had too much trouble since, we basically did the same coding process on homework 1. This time, the questions just more specific on what the accuracy if the final answer should be. I especially enjoyed the atomic weight code since. I'm not too sure why but I found it to be enjoyable. Asking for the user input and printing the results were pretty cool.
// main code without any modfication //
#include <stdio.h>
#include <math.h>
int main(void)
{
/* declare variables */
double femur, femur_m, femur_f, humerus, humerus_m, humerus_f;
/* Input from user */
printf("enter length of femur: \n");
scanf("%lf", &femur);
printf("enter length of humerus: \n");
scanf("%lf", &humerus);
/* computing height based on humerus and femur */
femur_f = femur*1.94 + 28.7;
femur_m = femur*1.88 + 32;
humerus_f = humerus*2.8 +28.2;
humerus_m = humerus*2.8 +27.9;
/* print height estimates */
printf("\nheight estimates in inches \n");
printf("femur female estimates: %5.1f \n",femur_f);
printf("femur male estimates: %5.1f \n",femur_m);
printf("humerus female estimates: %5.1f \n", humerus_f);
printf("humerus male estimates: %5.1f \n", humerus_m);
return 0;
}
#problem1
#include <stdio.h>
#include <math.h>
int main(void)
{
/* declare variables */
double femur, femur_m, femur_f, humerus, humerus_m, humerus_f;
/* Input from user */
printf("enter length of femur in inches.: \n");
scanf("%lf", &femur);
printf("enter length of humerus in inches: \n");
scanf("%lf", &humerus);
/* computing height based on humerus and femur */
femur_f = (femur*1.94 + 28.7)/12;
femur_m = (femur*1.88 + 32)/12;
humerus_f = (humerus*2.8 +28.2)/12;
humerus_m = (humerus*2.8 +27.9)/12;
/* print height estimates */
printf("\nheight estimates in feet \n");
printf("femur female estimates: %5.1f \n",femur_f);
printf("femur male estimates: %5.1f \n",femur_m);
printf("humerus female estimates: %5.1f \n", humerus_f);
printf("humerus male estimates: %5.1f \n", humerus_m);
return 0;
}
#problem2
#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 feet. \n");
printf("Enter femur length: \n");
scanf("%lf",&femur);
printf("Enter humerus length: \n");
scanf("%lf",&humerus);
/* Compute height estimates. */
femur_ht_f = ((femur*12*1.94) + 28.7)/12;
femur_ht_m = ((femur*12*1.88) + 32)/12;
humerus_ht_f = ((humerus*12*2.8) + 28.2)/12;
humerus_ht_m = ((humerus*12*2.9) + 27.9)/12;
/* Print height estimates. */
printf("\nHeight Estimates in Feet \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;
}
#problem1
#include <stdio.h>
#include <math.h>
int main(void)
{
/* declare variable*/
double o,c,n,s,h,mwg;
o = 15.9994,c = 12.011, n = 14.00674, s = 32.066,h = 1.00794;
/* calculate the moleculare weight */
mwg = 2*o + 2*c + n + 5*h;
/* display the molecular weight */
printf("Molecular weight of glycine: %5.3f", mwg );
return 0;
}
#problem2
#include <stdio.h>
#include <math.h>
int main(void)
{
/* declare variable*/
double o,c,n,s,h,mw_glutamic, mw_glatamine;
o = 15.9994,c = 12.011, n = 14.00674, s = 32.066,h = 1.00794;
/* calculate the moleculare weight */
mw_glutamic = 4*o + 5*c + n + 8*h;
mw_glatamine = 3*o + 2*n +10*h;
/* display the molecular weight */
printf("Molecular weight of glycine: %5.3f\n", mw_glutamic );
printf("Molecular weight of glutamine: %5.3f", mw_glatamine );
return 0;
}
#problem3
#include <stdio.h>
#include <math.h>
int main(void)
{
/* declare variable*/
double o,c,n,s,h,mw,o_num,c_num,n_num,s_num,h_num;
o = 15.9994,c = 12.011, n = 14.00674, s = 32.066,h = 1.00794;
/* user input */
printf("numbers of Oxygen \n");
scanf("%lf",&o_num);
printf("numbers of carbon \n");
scanf("%lf",&c_num);
printf("numbers of Nitrogen \n");
scanf("%lf",&n_num);
printf("numbers of Sulfur \n");
scanf("%lf",&s_num);
printf("numbers of Hydrogen \n");
scanf("%lf",&h_num);
/* calculate the moleculare weight */
mw = (o*o_num + c*c_num + n*n_num + s*s_num +h*h_num);
/* display the molecular weight */
printf("Molecular weight of the amino acid: %5.3f\n", mw );
return 0;
}
#problem4
#include <stdio.h>
#include <math.h>
int main(void)
{
/* declare variable*/
double o,c,n,s,h,mw,o_num,c_num,n_num,s_num,h_num;
o = 15.9994,c = 12.011, n = 14.00674, s = 32.066,h = 1.00794;
/* user input */
printf("numbers of Oxygen \n");
scanf("%lf",&o_num);
printf("numbers of carbon \n");
scanf("%lf",&c_num);
printf("numbers of Nitrogen \n");
scanf("%lf",&n_num);
printf("numbers of Sulfur \n");
scanf("%lf",&s_num);
printf("numbers of Hydrogen \n");
scanf("%lf",&h_num);
/* calculate the moleculare weight */
mw = (o*o_num + c*c_num + n*n_num + s*s_num +h*h_num)/(o_num + c_num + n_num + s_num + h_num);
/* display the molecular weight */
printf("Average molecular weight of the amino acid: %5.3f\n", mw );
return 0;
}
// main code without any modfication //
#include <stdio.h>
#include <math.h>
int main(void)
{
/* declare variables */
double femur, femur_m, femur_f, humerus, humerus_m, humerus_f;
/* Input from user */
printf("enter length of femur: \n");
scanf("%lf", &femur);
printf("enter length of humerus: \n");
scanf("%lf", &humerus);
/* computing height based on humerus and femur */
femur_f = femur*1.94 + 28.7;
femur_m = femur*1.88 + 32;
humerus_f = humerus*2.8 +28.2;
humerus_m = humerus*2.8 +27.9;
/* print height estimates */
printf("\nheight estimates in inches \n");
printf("femur female estimates: %5.1f \n",femur_f);
printf("femur male estimates: %5.1f \n",femur_m);
printf("humerus female estimates: %5.1f \n", humerus_f);
printf("humerus male estimates: %5.1f \n", humerus_m);
return 0;
}
#problem1
#include <stdio.h>
#include <math.h>
int main(void)
{
/* declare variables */
double femur, femur_m, femur_f, humerus, humerus_m, humerus_f;
/* Input from user */
printf("enter length of femur in inches.: \n");
scanf("%lf", &femur);
printf("enter length of humerus in inches: \n");
scanf("%lf", &humerus);
/* computing height based on humerus and femur */
femur_f = (femur*1.94 + 28.7)/12;
femur_m = (femur*1.88 + 32)/12;
humerus_f = (humerus*2.8 +28.2)/12;
humerus_m = (humerus*2.8 +27.9)/12;
/* print height estimates */
printf("\nheight estimates in feet \n");
printf("femur female estimates: %5.1f \n",femur_f);
printf("femur male estimates: %5.1f \n",femur_m);
printf("humerus female estimates: %5.1f \n", humerus_f);
printf("humerus male estimates: %5.1f \n", humerus_m);
return 0;
}
#problem2
#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 feet. \n");
printf("Enter femur length: \n");
scanf("%lf",&femur);
printf("Enter humerus length: \n");
scanf("%lf",&humerus);
/* Compute height estimates. */
femur_ht_f = ((femur*12*1.94) + 28.7)/12;
femur_ht_m = ((femur*12*1.88) + 32)/12;
humerus_ht_f = ((humerus*12*2.8) + 28.2)/12;
humerus_ht_m = ((humerus*12*2.9) + 27.9)/12;
/* Print height estimates. */
printf("\nHeight Estimates in Feet \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;
}
#problem2(second way by creating a new variable)
#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, feet_in_conv_humurus, feet_in_conv_femur;
/* Get user input from the keyboard. */
printf("Enter Values in feet. \n");
printf("Enter femur length: \n");
scanf("%lf",&feet_in_conv_femur);
printf("Enter humerus length: \n");
scanf("%lf",&feet_in_conv_humurus);
/* Compute height estimates. */
humerus = feet_in_conv_humurus*12;
femur = feet_in_conv_femur*12 ;
femur_ht_f = ((femur*1.94) + 28.7)/12;
femur_ht_m = ((femur*1.88) + 32)/12;
humerus_ht_f = ((humerus*2.8) + 28.2)/12;
humerus_ht_m = ((humerus*2.9) + 27.9)/12;
/* 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("\n Height estimates in Feet");
/* Exit program. */
return 0;
}
#problem3
#include <stdio.h>
#include <math.h>
int main(void)
{
/* declare variables */
double femur, femur_m, femur_f, humerus, humerus_m, humerus_f,femur_f_feet,femur_m_feet, humerus_f_feet,humerus_m_feet;
/* Input from user */
printf("enter length of femur in inches.: \n");
scanf("%lf", &femur);
printf("enter length of humerus in inches.: \n");
scanf("%lf", &humerus);
/* computing height based on humerus and femur */
femur_f = (femur*1.94 + 28.7);
femur_m = (femur*1.88 + 32);
humerus_f = (humerus*2.8 +28.2);
humerus_m = (humerus*2.8 +27.9);
femur_f_feet = ((femur*1.94) + 28.7)/12;
femur_m_feet = ((femur*1.88) + 32)/12;
humerus_f_feet = ((humerus*2.8) + 28.2)/12;
humerus_m_feet = ((humerus*2.9) + 27.9)/12;
/* print height estimates */
printf("\nheight estimates in feet \n");
printf("femur female estimates: %5.2f \n",femur_f);
printf("femur male estimates: %5.2f \n",femur_m);
printf("humerus female estimates: %5.2f \n", humerus_f);
printf("humerus male estimates: %5.2f \n", humerus_m);
printf("\nHeight estimates in Feet\n");
printf("Femur Female Estimate: %5.1f \n",femur_f_feet);
printf("Femur Male Estimate: %5.1f \n",femur_m_feet);
printf("Humerus Female Estimate: %5.1f \n",humerus_f_feet);
printf("Humerus Male Estimate: %5.1f \n",humerus_m_feet);
return 0;
}
#problem4
#include <stdio.h>
#include <math.h>
int main(void)
{
/* declare variables */
double femur, femur_m, femur_f, humerus, humerus_m, humerus_f,femur_feet,humerus_feet,femur_f_feet,femur_m_feet,humerus_f_feet,humerus_m_feet,humerus_feet_input,femur_feet_input;
/* Input from user */
printf("enter length of femur in inches.: \n");
scanf("%lf", &femur);
printf("enter length of humerus in inches.: \n");
scanf("%lf", &humerus);
printf("enter length of femur in feet.: \n");
scanf("%lf", &femur_feet);
printf("enter length of humerus in feet.: \n");
scanf("%lf", &humerus_feet);
/* computing height based on humerus and femur */
femur_f = (femur*1.94 + 28.7);
femur_m = (femur*1.88 + 32);
humerus_f = (humerus*2.8 +28.2);
humerus_m = (humerus*2.8 +27.9);
femur_feet_input = femur_feet*12;
humerus_feet_input = humerus_feet*12;
femur_f_feet = ((femur_feet_input*1.94) + 28.7)/12;
femur_m_feet = ((femur_feet_input*1.88) + 32)/12;
humerus_f_feet = ((humerus_feet_input*2.8) + 28.2)/12;
humerus_m_feet = ((humerus_feet_input*2.9) + 27.9)/12;
/* print height estimates */
printf("\nheight estimates in inches \n");
printf("femur female estimates: %5.2f \n",femur_f);
printf("femur male estimates: %5.2f \n",femur_m);
printf("humerus female estimates: %5.2f \n", humerus_f);
printf("humerus male estimates: %5.2f \n", humerus_m);
printf("\nHeight estimates in Feet\n");
printf("Femur Female Estimate: %5.1f \n",femur_f_feet);
printf("Femur Male Estimate: %5.1f \n",femur_m_feet);
printf("Humerus Female Estimate: %5.1f \n",humerus_f_feet);
printf("Humerus Male Estimate: %5.1f \n",humerus_m_feet);
return 0;
}
#problem5
#include <stdio.h>
#include <math.h>
int main(void)
{
/* declare variables */
double femur, femur_m, femur_f, humerus, humerus_m, humerus_f,femur_cm, humerus_cm;
/* Input from user */
printf("enter length of femur in centimeters.: \n");
scanf("%lf", &femur_cm);
printf("enter length of humerus in centimeters: \n");
scanf("%lf", &humerus_cm);
/* computing height based on humerus and femur */
femur = femur_cm/2.54;
humerus = humerus_cm/2.54;
femur_f = (femur*1.94 + 28.7)*2.54;
femur_m = (femur*1.88 + 32)*2.54;
humerus_f = (humerus*2.54 +28.2)*2.54;
humerus_m = (humerus*2.54 +27.9)*2.54;
/* print height estimates */
printf("\nheight estimates in centimeters \n");
printf("femur female estimates: %5.1f \n",femur_f);
printf("femur male estimates: %5.1f \n",femur_m);
printf("humerus female estimates: %5.1f \n", humerus_f);
printf("humerus male estimates: %5.1f \n", humerus_m);
return 0;
}
#problem1
#include <stdio.h>
#include <math.h>
int main(void)
{
/* declare variable*/
double o,c,n,s,h,mwg;
o = 15.9994,c = 12.011, n = 14.00674, s = 32.066,h = 1.00794;
/* calculate the moleculare weight */
mwg = 2*o + 2*c + n + 5*h;
/* display the molecular weight */
printf("Molecular weight of glycine: %5.3f", mwg );
return 0;
}
#problem2
#include <stdio.h>
#include <math.h>
int main(void)
{
/* declare variable*/
double o,c,n,s,h,mw_glutamic, mw_glatamine;
o = 15.9994,c = 12.011, n = 14.00674, s = 32.066,h = 1.00794;
/* calculate the moleculare weight */
mw_glutamic = 4*o + 5*c + n + 8*h;
mw_glatamine = 3*o + 2*n +10*h;
/* display the molecular weight */
printf("Molecular weight of glycine: %5.3f\n", mw_glutamic );
printf("Molecular weight of glutamine: %5.3f", mw_glatamine );
return 0;
}
#problem3
#include <stdio.h>
#include <math.h>
int main(void)
{
/* declare variable*/
double o,c,n,s,h,mw,o_num,c_num,n_num,s_num,h_num;
o = 15.9994,c = 12.011, n = 14.00674, s = 32.066,h = 1.00794;
/* user input */
printf("numbers of Oxygen \n");
scanf("%lf",&o_num);
printf("numbers of carbon \n");
scanf("%lf",&c_num);
printf("numbers of Nitrogen \n");
scanf("%lf",&n_num);
printf("numbers of Sulfur \n");
scanf("%lf",&s_num);
printf("numbers of Hydrogen \n");
scanf("%lf",&h_num);
/* calculate the moleculare weight */
mw = (o*o_num + c*c_num + n*n_num + s*s_num +h*h_num);
/* display the molecular weight */
printf("Molecular weight of the amino acid: %5.3f\n", mw );
return 0;
}
#problem4
#include <stdio.h>
#include <math.h>
int main(void)
{
/* declare variable*/
double o,c,n,s,h,mw,o_num,c_num,n_num,s_num,h_num;
o = 15.9994,c = 12.011, n = 14.00674, s = 32.066,h = 1.00794;
/* user input */
printf("numbers of Oxygen \n");
scanf("%lf",&o_num);
printf("numbers of carbon \n");
scanf("%lf",&c_num);
printf("numbers of Nitrogen \n");
scanf("%lf",&n_num);
printf("numbers of Sulfur \n");
scanf("%lf",&s_num);
printf("numbers of Hydrogen \n");
scanf("%lf",&h_num);
/* calculate the moleculare weight */
mw = (o*o_num + c*c_num + n*n_num + s*s_num +h*h_num)/(o_num + c_num + n_num + s_num + h_num);
/* display the molecular weight */
printf("Average molecular weight of the amino acid: %5.3f\n", mw );
return 0;
}
Comments
Post a Comment