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",£s);
/* 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",°rees_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",°rees_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",°rees_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;
}
/*--------------------------------------------------------------------*/
No comments:
Post a Comment