Search This Blog(textbook name or author as the keywords)You can cantact me by the Contact Form

9/13/14

Engineering Problem Solving with C, 4/E Etter solutions manual

Engineering Problem Solving with C, 4/E Etter solutions manual

Chapter 2

/*--------------------------------------------------------------------*/

/* Problem chapter2_21 */

/* */

/* This program converts miles to kilometers. */

#include <stdio.h>

int main(void)

{

/* Declare variables. */

double miles, kilometers;

/* Enter number of miles from the keyboard. */

printf("Enter the number of miles: \n");

scanf("%lf",&miles);

/* Compute the number of kilometers equal to the specified miles. */

kilometers = 1.6093440*miles;

/* Print the number of kilometers. */

printf("%8.3f miles = %8.3f kilometers \n",miles,kilometers);

/* Exit program. */

return 0;

}

/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/

/* Problem chapter2_22 */

/* */

/* This program converts meters to miles. */

#include <stdio.h>

int main(void)

{

/* Declare variables. */

double miles, meters;

/* Enter number of meters from the keyboard. */

printf("Enter the number of meters: \n");

scanf("%lf",&meters);

/* Compute the number of miles equal to the specified meters. */

miles = meters/1609.3440;

/* Print the number of miles. */

printf("%8.3f meters = %8.3f miles \n",meters,miles);

/* Exit program. */

return 0;

}

/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/

/* Problem chapter2_23 */

/* */

/* This program converts pounds to kilograms. */

#include <stdio.h>

int main(void)

{

/* Declare variables. */

double pounds, kilograms;

/* Enter number of pounds from the keyboard. */

printf("Enter the number of pounds: \n");

scanf("%lf",&pounds);

/* Compute number of kilograms equal to the specified pounds. */

kilograms = pounds/2.205;

/* Print the number of kilograms. */

printf("%8.3f pounds = %8.3f kilograms \n",pounds,kilograms);

/* Exit program. */

return 0;

}

/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/

/* Problem chapter2_24 */

/* */

/* This program converts newtons to pounds. */

#include <stdio.h>

int main(void)

{

/* Declare variables. */

double pounds, newtons;

/* Enter number of newtons from the keyboard. */

printf("Enter the number of newtons: \n");

scanf("%lf",&newtons);

/* Compute number of pounds equal to the specified newtons. */

pounds = newtons/4.448;

/* Print the number of pounds. */

printf("%8.3f newtons = %8.3f pounds \n",newtons,pounds);

/* Exit program. */

return 0;

}

/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/

/* Problem chapter2_25 */

/* */

/* This program converts degrees Fahrenheit to degrees Rankin. */

#include <stdio.h>

int main(void)

{

/* Declare variables. */

double degrees_F, degrees_R;

/* Enter temperture in degrees Fahrenheit from the keyboard. */

printf("Enter the temperature in degrees Fahrenheit: \n");

scanf("%lf",&degrees_F);

/* Compute the equivalent temperature in degrees Rankin */

/* from the given temperature. */

degrees_R = degrees_F + 459.67;

/* Print the temperatures. */

printf("%8.3f degrees Fahrenheit = %8.3f degrees Rankin \n",

degrees_F,degrees_R);

/* Exit program. */

return 0;

}

/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/

/* Problem chapter2_26 */

/* */

/* This program converts degrees Celsius to degrees Rankin. */

#include <stdio.h>

int main(void)

{

/* Declare variables. */

double degrees_C, degrees_R, degrees_F;

/* Enter temperture in degrees Celsius from the keyboard. */

printf("Enter the temperature in degrees Celsius: \n");

scanf("%lf",&degrees_C);

/* Compute the equivalent temperature in degrees Rankin */

/* from the given temperature. */

degrees_F = (9.0/5.0)*degrees_C + 32;

degrees_R = degrees_F + 459.67;

/* Print the temperatures. */

printf("%8.3f degrees Celsius = %8.3f degrees Rankin \n",

degrees_C,degrees_R);

/* Exit program. */

return 0;

}

/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/

/* Problem chapter2_27 */

/* */

/* This program converts degrees Kelvin to degrees Fahrenheit. */

#include <stdio.h>

int main(void)

{

/* Declare variables. */

double degrees_R, degrees_K, degrees_F;

/* Enter temperture in degrees Kelvin from the keyboard. */

printf("Enter the temperature in degrees Kelvin: \n");

scanf("%lf",&degrees_K);

/* Compute the equivalent temperature in degrees Fahrenheit */

/* from the given temperature. */

degrees_R = (9.0/5.0)*degrees_K;

degrees_F = degrees_R - 459.67;

/* Print the temperatures. */

printf("%8.3f degrees Kelvin = %8.3f degrees Fahrenheit \n",

degrees_K,degrees_F);

/* Exit program. */

return 0;

}

/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/

/* Problem chapter2_28 */

/* */

/* This program finds the area of a rectangle. */

#include <stdio.h>

int main(void)

{

/* Declare variables. */

double a, b, area;

/* Enter the lengths of sides of the rectangle. */

printf("Enter the lengths of the sides of the rectangle: \n");

scanf("%lf %lf",&a,&b);

/* Compute the area of the rectangle. */

area = a*b;

/* Print the value of the area. */

printf("The area of a rectangle with sides %5.3f and %5.3f"

" is %5.3f. \n",a,b,area);

/* Exit program. */

return 0;

}

/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/

/* Problem chapter2_29 */

/* */

/* This program finds the area of a triangle. */

#include <stdio.h>

int main(void)

{

/* Declare variables. */

double h, b, area;

/* Enter the base and the height of the triangle. */

printf("Enter the base and the height of the triangle: \n");

scanf("%lf %lf",&b,&h);

/* Compute the area of the triangle. */

area = 0.5*b*h;

/* Print the value of the area. */

printf("The area of a triangle with base %5.3f and height %5.3f "

"is %5.3f. \n",b,h,area);

/* Exit program. */

return 0;

}

/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/

/* Problem chapter2_30 */

/* */

/* This program finds the area of a circle. */

#include <stdio.h>

#define PI 3.141593

int main(void)

{

/* Declare variables. */

double r, area;

/* Enter the radius. */

printf("Enter the radius of the circle: \n");

scanf("%lf",&r);

/* Compute the area of the circle. */

area = PI*r*r;

/* Print the value of the area. */

printf("The area of a cirlce with radius %5.3f is %5.3f. \n",

r,area);

/* Exit program. */

return 0;

}

/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/

/* Problem chapter2_31 */

/* */

/* This program computes the area of a sector of a circle when */

/* theta is the angle in radians between the radii. */

#include <stdio.h>

int main(void)

{

/* Declare variables. */

double theta, r, area;

/* Enter the lengths of the radii and */

/* the angle between them. */

printf("Enter the length of the radii and the angle "

"(in radians) between them: \n");

scanf("%lf %lf",&r,&theta);

/* Compute the area of the sector. */

area = (r*r*theta)/2.0;

/* Print the value of the area. */

printf("The area of sector is %5.3f. \n",area);

/* Exit program. */

return 0;

}

/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/

/* Problem chapter2_32 */

/* */

/* This program computes the area of a sector of a circle when */

/* d is the angle in degrees between the radii. */

#include <stdio.h>

#define PI 3.141593

int main(void)

{

/* Declare variables. */

double d, theta, r, area;

/* Enter the length of the radii and the angle between them. */

printf("Enter the length of the radii and the angle"

" (in degrees) between them: \n");

scanf("%lf %lf",&r,&d);

/* Compute the area of the sector. */

theta = (d*PI)/180;

area = (r*r*theta)/2.0;

/* Print the value of the area. */

printf("The area of sector is %5.3f. \n",area);

/* Exit program. */

return 0;

}

/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/

/* Problem chapter2_33 */

/* */

/* This program computes the area of an */

/* ellipse with semiaxes a and b. */

#include <stdio.h>

#define PI 3.141593

int main(void)

{

/* Declare variables. */

double a, b, area;

/* Enter the length of the semiaxes. */

printf("Enter the length of the semiaxes: \n");

scanf("%lf %lf",&a,&b);

/* Compute the area of the ellipse. */

area = PI*a*b;

/* Print the value of the area. */

printf("The area of an ellipse with semiaxes %5.3f and %5.3f"

" is %5.3f. \n",a,b,area);

/* Exit program. */

return 0;

}

/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/

/* Problem chapter2_34 */

/* */

/* This program computes the area of the surface */

/*ΓΏ of a sphere of radius r. */

#include <stdio.h>

#define PI 3.141593

int main(void)

{

/* Declare variables. */

double r, area;

/* Enter the radius of the sphere. */

printf("Enter the radius of the sphere: \n");

scanf("%lf",&r);

/* Compute the area of the sphere. */

area = 4.0*PI*r*r;

/* Print the value of the area. */

printf("The area of a sphere with radius %5.3f"

" is %5.3f. \n",r,area);

/* Exit program. */

return 0;

}

/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/

/* Problem chapter2_35 */

/* */

/* This program computes the volume of a sphere of radius r. */

#include <stdio.h>

#define PI 3.141593

int main(void)

{

/* Declare variables. */

double r, volume;

/* Enter the radius of the sphere. */

printf("Enter the radius of the sphere: \n");

scanf("%lf",&r);

/* Compute the volume of the sphere. */

volume = (4.0/3.0)*PI*r*r*r;

/* Print the volume. */

printf("The volume of a sphere with radius %5.3f is %5.3f. \n",

r,volume);

/* Exit program. */

return 0;

}

/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/

/* Problem chapter2_36 */

/* */

/* This program computes the volume of a cylinder */

/* of radius r and height h. */

#include <stdio.h>

#define PI 3.141593

int main(void)

{

/* Declare variables. */

double r, h, volume;

/* Enter the radius and height of the cylinder. */

printf("Enter the radius and the height of the cylinder: \n");

scanf("%lf %lf",&r,&h);

/* Compute the volume of the cylinder. */

volume = PI*r*r*h;

/* Print the volume. */

printf("The volume of a cylinder of radius %5.3f and "

"height %5.3f is %5.3f. \n",r,h,volume);

/* Exit program. */

return 0;

}

/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/

/* Problem chapter2_37 */

/* */

/* This program computes the molecular weight of the */

/* amino acid glycine. */

#include <stdio.h>

/* Defines symbolic constants for the appropriate atomic weights. */

#define OXYGEN 15.9994

#define CARBON 12.011

#define NITROGEN 14.00674

#define HYDROGEN 1.00794

int main(void)

{

/* Declare variables. */

double molecular_weight;

/* Compute the molecular weight of glycine. */

molecular_weight = (2*OXYGEN) + (2*CARBON) +

NITROGEN + (5*HYDROGEN);

/* Print the molecular weight. */

printf("The molecular weight of glycine is %4.3f. \n",

molecular_weight);

/* Exit program. */

return 0;

}

/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/

/* Problem chapter2_38 */

/* */

/* This program computes the molecular weights of the */

/* amino acid glutamic and glutamine. */

#include <stdio.h>

/* Defines symbolic constants for the appropriate atomic weights. */

#define OXYGEN 15.9994

#define CARBON 12.011

#define NITROGEN 14.00674

#define HYDROGEN 1.00794

int main(void)

{

/* Declare variables. */

double molecular_weight1, molecular_weight2;

/* Compute the molecular weights of glutamic and glutamine. */

molecular_weight1 = (4*OXYGEN) + (5*CARBON) +

NITROGEN + (8*HYDROGEN);

molecular_weight2 = (3*OXYGEN) + (5*CARBON) +

(2*NITROGEN) + (10*HYDROGEN);

/* Print the molecular weights. */

printf("The molecular weight of glutamic is %4.3f. \n",

molecular_weight1);

printf("The molecular weight of glutamine is %4.3f. \n",

molecular_weight2);

/* Exit program. */

return 0;

}

/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/

/* Problem chapter2_39 */

/* */

/* This program computes the molecular weight of a particular */

/* amino acid given the number of atoms for each of the five */

/* elements found in the amino acid. */

#include <stdio.h>

/* Defines symbolic constants for the appropriate atomic weights. */

#define OXYGEN 15.9994

#define CARBON 12.011

#define NITROGEN 14.00674

#define HYDROGEN 1.00794

#define SULFUR 32.066

int main(void)

{

/* Declare variable. */

int no_oxy, no_carbon, no_nitro, no_hydro, no_sulfur;

double molecular_weight;

/* Enter the number of atoms for each of the five elements. */

printf("Enter the number of oxygen atoms found "

"in the amino acid. \n");

scanf("%i",&no_oxy);

printf("Enter the number of carbon atoms. \n");

scanf("%i",&no_carbon);

printf("Enter the number of nitrogen atoms. \n");

scanf("%i",&no_nitro);

printf("Enter the number of sulfur atoms. \n");

scanf("%i",&no_sulfur);

printf("Enter the number of hydrogen atoms. \n");

scanf("%i",&no_hydro);

/* Compute the molecular weight. */

molecular_weight = (no_oxy*OXYGEN) + (no_carbon*CARBON) +

(no_nitro*NITROGEN) + (no_sulfur*SULFUR) +

(no_hydro*HYDROGEN);

/* Print the molecular weight. */

printf("The molecular weight of this particular amino acid"

" is %4.3f. \n",molecular_weight);

/* Exit program. */

return 0;

}

/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/

/* Problem chapter2_40 */

/* */

/* This program computes the average atomic weight of the atoms */

/* found in a particular amino acid given the number of atoms for */

/* each of the five elements found in amino acid. */

#include <stdio.h>

/* Defines symbolic constants for the appropriate atomic weights. */

#define OXYGEN 15.9994

#define CARBON 12.011

#define NITROGEN 14.00674

#define HYDROGEN 1.00794

#define SULFUR 32.066

int main(void)

{

/* Declare variables. */

int no_oxy, no_carbon, no_nitro, no_hydro, no_sulfur, total_no;

double average_atomic_weight;

/* Enter the number of atoms for each of the five elements. */

printf("Enter the number of oxygen atoms found "

" in the amino acid. \n");

scanf("%i",&no_oxy);

printf("Enter the number of carbon atoms. \n");

scanf("%i",&no_carbon);

printf("Enter the number of nitrogen atoms. \n");

scanf("%i",&no_nitro);

printf("Enter the number of sulfur atoms. \n");

scanf("%i",&no_sulfur);

printf("Enter the number of hydrogen atoms. \n");

scanf("%i",&no_hydro);

/* Compute the average weight of the atoms. */

total_no = no_oxy + no_carbon + no_nitro + no_sulfur + no_hydro;

average_atomic_weight = ((no_oxy*OXYGEN) + (no_carbon*CARBON) +

(no_nitro*NITROGEN) + (no_sulfur*SULFUR) +

(no_hydro*HYDROGEN))/total_no;

/* Print the average atomic weight. */

printf("The average weight of the atoms in this particular amino "

"acid is %4.3f. \n",average_atomic_weight);

/* Exit program. */

return 0;

}

/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/

/* Problem chapter2_41 */

/* */

/* This program reads in a positive number and then computes */

/* the logarithm of that value to the base 2. */

#include <stdio.h>

#include <math.h>

int main(void)

{

/* Declare variables. */

double x, answer;

/* Enter a positive number. */

printf("Enter a positive number: \n");

scanf("%lf",&x);

/* Compute the logarithm to base 2. */

answer = log(x)/log(2.0);

/* Print the answer. */

printf("The logarithm of %5.3f to the base 2 is "

" %5.3f. \n",x,answer);

/* Exit program. */

return 0;

}

/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/

/* Problem chapter2_42 */

/* */

/* This program reads in a positive number and then computes */

/* the logarithm of that value to the base 8. */

#include <stdio.h>

#include <math.h>

int main(void)

{

/* Declare variables. */

double x, answer;

/* Enter a positive number. */

printf("Enter a positive number: \n");

scanf("%lf",&x);

/* Compute the logarithm to base 8. */

answer = log(x)/log(8.0);

/* Print the answer. */

printf("The logarithm of %5.3f to the base 8 is %5.3f. \n",

x,answer);

/* Exit program. */

return 0;

}

/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/

/* Problem chapter2_43 */

/* */

/* This program uses linear interpolation to compute the */

/* coefficient of lift for an angle from a wind tunnel test. */

#include <stdio.h>

int main(void)

{

/* Declare variables. */

double a, f_a, b, f_b, c, f_c;

/* Get user input from the keyboard. */

printf("Use degrees for all angle measurements. \n");

printf("Enter first angle and lift coefficient: \n");

scanf("%lf %lf",&a,&f_a);

printf("Enter second angle and lift coefficient: \n");

scanf("%lf %lf",&c,&f_c);

printf("Enter new angle: \n")"

scanf("%lf",&b);

/* Use linear interpolation to compute new lift. */

f_b = f_a + (b-a)/(c-a)*(f_c - f_a);

/* Print new lift value. */

printf("New lift coefficient: %6.3f \n",f_b);

/* Exit program. */

return 0;

}

/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/

/* Problem chapter2_44 */

/* */

/* This program uses linear interpolation to compute the */

/* coefficient of lift for an angle from a wind tunnel test. */

/* The new angle is printed in degrees and radians. */

#include <stdio.h>

#define PI 3.141593

int main(void)

{

/* Declare variables. */

double a, f_a, b, f_b, c, f_c, b_radians;

/* Get user input from the keyboard. */

printf("Use degrees for all angle measurements. \n");

printf("Enter first angle and lift coefficient: \n");

scanf("%lf %lf",&a,&f_a);

printf("Enter second angle and lift coefficient: \n");

scanf("%lf %lf",&c,&f_c);

printf("Enter new angle: \n")"

scanf("%lf",&b);

/* Use linear interpolation to compute new lift. */

f_b = f_a + (b-a)/(c-a)*(f_c - f_a);

b_radians = b*PI/180;

/* Print new lift value. */

printf("New angle in radians: %6.2f \n",b_radians);

printf("New lift coefficient: %6.3f \n",f_b);

/* Exit program. */

return 0;

}

/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/

/* Problem chapter2_45 */

/* */

/* This program uses linear interpolation to compute the */

/* angle for a coefficient of lift from a wind tunnel test. */

#include <stdio.h>

int main(void)

{

/* Declare variables. */

double a, f_a, b, f_b, c, f_c;

/* Get user input from the keyboard. */

printf("Use degrees for all angle measurements. \n");

printf("Enter first lift coefficient and angle: \n");

scanf("%lf %lf",&a,&f_a);

printf("Enter second lift coefficient and angle: \n");

scanf("%lf %lf",&c,&f_c);

printf("Enter new coefficient: \n")"

scanf("%lf",&b);

/* Use linear interpolation to compute new angle. */

f_b = f_a + (b-a)/(c-a)*(f_c - f_a);

/* Print new angle. */

printf("New angle, in degrees: %6.3f \n",f_b);

/* Exit program. */

return 0;

}

/*--------------------------------------------------------------------*/

No comments:

Post a Comment

Linkwithin

Related Posts Plugin for WordPress, Blogger...