chapter 2 program 1
//Christopher Poole
//preprocessors directories
#include<stdio.h> //provides Input Output features
#define reimburse 0.350
//function main
//24/01/10 23:36
int
main(void)
{
char pause;
//enter data below this line
int odom1;
int odom2;
int mileage;
double money;
int mileage1;
printf("Enter begining Odometer Reading : ");
scanf("%d", &odom1);
printf("Enter ending Odometer Reading : ");
scanf("%d", &odom2);
mileage=odom2-odom1;
printf("\n\n You traveled %d miles\n ", mileage);
mileage1=mileage;
money=mileage1 * reimburse;
printf("\n At .35 cent a mile. You will be Reimbursed %.2f\n\n\n\n", money);
//enter data above this line
printf("Press Enter to Close the Window\n");
scanf("%c", &pause);
scanf("%c", &pause);
return 0;
}
chapter 2 program 2
chapter 2 program 3
//Program 3 pg 103
//This program estimates the temperature in a freezer based on elasped time
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int
main(void)
{
double hours, minutes, convert, time, temperature;
%2
chapter 2 program 4
//Program 4
#include <stdio.h>
#include <stdlib.h>
int
main(void)
{
double fahrenheit; /*temp. in degrees Fahrenheit */
double celsius; /* temp. in degrees Celcius */
/* Get the temp in fahrenheit */
printf("Enter the temp in degrees fahrenheit: ");
scanf("%1f", &fahrenheit);
/*Convert to degrees Celcius */
celsius = fahrenheit - 32;
/* Display the degrees in Celcius */
printf("That is %f degrees Celsius.\n", celsius);
system("PAUSE");
return (0);
}
chapter 2 program 5
/*Robbie Taylor, Chase Sigmon, Jesse Rosenberg, Joe Keip*/
#include <stdio.h>
int
main(void)
{
double ml; /* milliliters */
double min; /* minutes */
double hours; /* hours */
double mlph; /* milliliters per hour */
printf("Enter amount of fluid in milliliters >");
scanf("%lf", &ml);
printf("Enter amount of time in minutes >");
scanf("%lf", &min);
hours = (min / 60.0);
mlph = ml / hours;
printf("VTBI: %.0f ml\n", ml);
printf("Rate: %.0f ml/hr\n", mlph);
system("PAUSE");
return (0);
}
chapter 2 program 6
# include <stdio.h>
# include <stdlib.h>
// File: MontgomeryNathanJan25.c
// Author: Nathan Montgomery
// Date: January 26, 2010
// Course: CSCI 140 - 03 Dr. Yessick
// Detail: Number 6 Chapter 2
int
main(void)
{
double needed, current, finalCounts, finalScore, diff, finalCounts2;
printf("Enter minimum average required: ");
scanf("%lf", &needed);
printf("Enter Current average in the course: ");
scanf("%lf", ¤t);
printf("Enter how much the final counts for the final grade: ");
scanf("%lf", &finalCounts);
if (finalCounts > 1)
finalCounts /= 100; //shorthand for fc = fc / 100;
&nb
chapter 2 program 7
chapter 2 program 8
//Program 8. Finds the cost of installation and amount of liters saved
#include <stdio.h>
#include <stdlib.h>
//function main
#define PPT 3
#define COI 150
#define New_Liter_Per_Flush 2
#define Exist_Liter_Per_Flush 15
#define FPD 14
int
main(void)
{
double population,
Lit_Sav, cost;
double Old_LPD,
New_LPD;
/* Get the amount of people. */
printf("Enter the number of people: ");
scanf("%1f", &population);
/* Computes the cost of installation*/
cost = COI * population / PPT;
/* Displays the cost of installation */
printf("Cost of installing new toilets is %7.2.3f dollars.\n", cost);
/* Computes the old amount of liters used per day */
Old_LPD = FPD * Exist_Liter_Per_Flush;
/* Computes the new amount of liters used per day */
New_LPD = FPD * New_Liter_Per_Flush;
/* Computes the liters saved */
Lit_Sav = Old_LPD - New_LPD;
/* Displays the liters saved */
printf("The amount of liters that will be saved is %.2f liters.\n",Lit_Sav);
system("PAUSE");
return (0);
}
chapter 2 program 9
chapter 2 program 10
#include <stdio.h>
/* Chase Sigmon, Robbie Taylor, Jesse Rosenberg, Joe Keip */
int
main(void)
{
double x1; /* input - first x coordinate */
double y1; /* input - first y coordinate */
double x2; /* input - second x coordinate */
double y2; /* input - second y coordinate */
double slope; /* output - slope of bisector */
double midpointx; /* output - average of x coordinates */
double midpointy; /* output - average of y coordinates */
double reciprocal; /* output - negative reciprocal of slope */
double yintercept; /* output - place where the line intersects
the y axis */
printf("Enter x1 >");
scanf("%lf", &x1);
printf("Enter y1 >");
scanf("%lf", &y1);
printf("Enter x2 >");
scanf("%lf", &x2);
printf("Enter y2 >");
scanf("%lf", &y2);
/* computing the slope and printing it out */
slope = (y1 - y2)/(x1 - x2);
printf("%.1f slope\n", slope);
/* compute midpoints and then print them out */
midpointx = (x1 + x2)/2;
midpointy = (y1 + y2)/2;
printf("(%.1f, %.1f) midpoint of bisector\n", midpointx, midpointy);
/* compute the negative reciprocal of the slope and print it out */
reciprocal = ((x1 - x2)/(y1 - y2)) * -1;
printf("%.1f negative reciprocal of slope\n", reciprocal);
/* compute the b value of y = mx + b, which is the y intercept */
/* then prints out the original coordinates and the equation
y = mx + b */
yintercept = (reciprocal * midpointx - midpointy) * -1;
printf("(%.1f, %.1f) , (%.1f, %.1f) original coordinates\n", x1, y1,
x2, y2);
printf("y = %.1fx + %.2f (y = mx + b)\n", reciprocal, yintercept);
/* While running the program if either the slope or the negative
reciprocal come out to be 0, that would mean you were either dividing
by 0 or using 0 to divide by. This in turn would cause the program to
fail and print out symbols rather than integers. EX: x1 = 7, y1 = 3,
x2 = 9, y2 = 3. These numbers would make the program output incorrect
%2
chapter 2 program 11
# include <stdio.h>
# include <stdlib.h>
// File: MontgomeryNathanJan25.c
// Author: Nathan Montgomery, Bobby Hemphill
// Date: January 26, 2010
// Course: CSCI 140 - 03 Dr. Yessick
// Detail: Problem 11 Chapter 2
int
main(void)
{
double m, n, hypo, side1, side2;
chapter 2 program 12
//Where as the language has begun