{ // Variables double n, result; cout << "Please enter a value: "; cin >> n; result = 1; while (n>1) { result = n * result; n = n - 1; } // end while

cout << "The answer is " << result << endl; } { // Variables double degF, degC; cout << "Enter degrees F: "; cin >> degF; degC = (5.0 / 9) * (degF - 32); cout << degF << " degrees F is equivalent to " << degC << " degrees C" << endl ; } { // Variables double degF, degC; cout << "Enter degrees F: "; cin >> degF; cout << degF << " degrees F is equivalent to " << (5.0 / 9) * (degF - 32) << " degrees C" << endl; } { // Variables double length, width, height, lSideHeight, lSideArea, wSideHeight, wSideArea, totalArea; cout << "Enter length, width, and height: "; cin >> length >> width >> height; lSideHeight = sqrt (sqr (height) + sqr(width/2)); lSideArea = (length * lSideHeight) / 2;

// Output result cout << "The total area is " << totalArea << " square units. cin >> length >> width >> height. height. lSideArea = (length * lSideHeight) / 2. lSideHeight. lSideArea. width. totalArea. . } { // Variables double length. width. cin >> length >> width >> height. // Obtain inputs from user cout << "Enter length." << endl. totalArea = 2 * lSideArea + 2 * wSideArea. and height: ". wSideHeight. } { // Variables double length. wSideArea = (width * wSideHeight) /2. wSideArea = (width * wSideHeight) /2. and height: ". cout << "The total area is " << totalArea << " square units. // Obtain inputs from user cout << "Enter length. wSideHeight = sqrt (sqr(height) + sqr(length/2)). totalArea = 2 * lSideArea + 2 * wSideArea." << endl. wSideArea.wSideHeight = sqrt (sqr(height) + sqr(length/2)). height. } { // Variables double length. width. // Do calculations lSideHeight = sqrt (sqr (height) + sqr(width/2))." << endl. width. // Output result cout << "The total area is " << totalArea << " square units. // Do calculations totalArea = (length * sqrt (sqr (height) + sqr(width/2))) + (width * sqrt (sqr(height) + sqr(length/2))). totalArea.

cin >> length >> width >> height. lng2 = lng2 * radsPerDeg. deltaLng. // Output result cout << "The total area is " << (length * sqrt (sqr (height) + sqr(width/2))) + (width * sqrt (sqr(height) + sqr(length/2))) < < " square units. cin >> lat1 >> lng1. width. lat2 = lat2 * radsPerDeg. // convert input quantities to radians lat1 = lat1 * radsPerDeg. // compute the difference in longitude deltaLng = fabs (lng1 .lng2).14159. // obtain input information cout << "Please enter lat and long of 1st point: ". radsPerDeg = pi / 180. lat2. angularDistance = acos (cosAngularDistance). distance. lng1. Output: The distance between the two points (in kms). cosAngularDistance.0. and height: ".707. } /* This program computes the distance between any two points on the earth.width. cout << "Please enter lat and long of 2nd point: ". */ { // Constants const double pi = 3. distance = earthRadiusInKm * angularDistance." << endl. . // apply the distance formulae cosAngularDistance = ( ( cos (lat1) * cos (lat2) * cos (deltaLng) ) + ( sin (lat1) * sin (lat2) ) ). Input: The latitudes and longitudes of the two points (in degrees). // Variables double lat1. angularDistance. height. earthRadiusInKm = 6377. cin >> lat2 >> lng2. lng1 = lng1 * radsPerDeg. Southerly latitudes and easterly longitudes are entered as negative s. lng2. // Obtain inputs from user cout << "Enter length.

cin >> fraction. while (fraction > 0) { age = . cout << "Enter C14 fraction: ". // number of calculated ages sum = 0.0001216. age. // Variables double fraction. } { // Constants const double C14Divider = 0. cout << "The sample is " << age << " years old. } // end while } { // Constants const double C14Divider = 0. } { // Constants const double C14Divider = 0. age. .0001216. cout << "Enter C14 fraction (0 or negative to terminate): ". // Variables double fraction. age = ." << endl. // Variables double fraction.0001216." << endl. cin >> fraction.cout << "The points are " << distance << " km apart. count = 0. cin >> fraction. cout << "The sample is " << age << " years old." << endl.(log(fraction) / C14Divider). // total of all calculated ages cout << "Enter C14 fraction (0 or negative to terminate): ". cout << "Enter C14 fraction (0 or negative to terminate): ". age.(log(fraction) / C14Divider).

// Variables double fraction.(log(fraction) / C14Divider).0001216. age. } // end while . sum = sum + age. } // end if } // end if cout << "Enter C14 fraction (0 or negative to terminate): ". // number of calculated ages sum = 0. if (age > highestAge) { highestAge = age.(log(fraction) / C14Divider). } // end while if (count != 0) { cout << "The average age is " << sum / count << endl." << endl. } else { age = . cout << "The sample is " << age << " years old. sum = sum + age. } // end if } { // Constants const double C14Divider = 0. // total of all calculated ages highestAge = -1. // impossibly low cout << "Enter C14 fraction (0 or negative to terminate): "." << endl. count = 0. count = count + 1. } else { age = . cin >> fraction. cout << "The sample is " << age << " years old. count = count + 1. cin >> fraction." << endl.cin >> fraction." << endl. cin >> fraction. while (fraction > 0) { // Process the data if (fraction > 1) { cout << "Invalid fraction ignored. while (fraction > 0) { // Process the data if (fraction > 1) { cout << "Invalid fraction ignored. } // end if cout << "Enter C14 fraction (0 or negative to terminate): ".

cin >> num1 >> num2. cout << "Please enter two numbers: ". test. } // end if } { // Variables double num1.test) !=0)) { test = test . } while (num2 != 0).test) != 0) || (fmod(num2. } // end while cout << "The GCD is " << test << endl. cout << "The GCD is " << num1 << endl. } { // Variables double num1. do { rem = fmod (num1. num2. rem. num2. num1 = num2. if /* the loop is guaranteed to exit because the condition is always false when "test" is 1. num2. num2). .1. cout << "Please enter two numbers: ". rem. if (num1 test = } else { test = } // end < num2) { num1. num2 = rem. } { // Variables double num1.if (count != 0) { cout << "The average age is " << sum / count << endl << "The greatest age is " << highestAge << endl. num2. */ while ((fmod(num1. cin >> num1 >> num2.

cin >> num1 >> num2. while (num1 != 0 || num2 != 0) { if ((num1 < 1) || (num2 < 1)) { cout << "Invalid values ignored. } else { do { rem = fmod (num1. cout << "Please enter two numbers (0 0 to terminate): ". } // end if cout << "Please enter two numbers (0 0 to terminate): ". num2. cout << "The GCD is " << num1 << endl. } while (num2 != 0). cin >> num1 >> num2." << endl. num1 = num2. num2). while (num1 != 0 || num2 != 0) { do { rem = fmod (num1. cout << "Please enter two numbers (0 0 to terminate): ".cout << "Please enter two numbers (0 0 to terminate): ". cin >> a >> b >> c. b. c. } while (num2 != 0). rem. cout << "Enter bar lengths: ". num2 = rem. cin >> num1 >> num2. cin >> num1 >> num2. cout << "The GCD is " << num1 << endl. num2 = rem. } // end while } { // Variables double num1. num2). } // end while } { // Variables double a. num1 = num2. .

sqrt(discriminant)) / (2 * a) << endl." << endl. cin >> a. } else { cout << "The bars can make a triangle. cin >> b >> c." << endl. } // end if } // end if cout << "Please enter a (0 to stop): ". while (a != 0) { cout << "Please enter b and c: ". cin >> b >> c." << endl. c. cin >> a. discriminant.if ((a >= b + c) || (b >= a + c) || (c >= a + b)) { cout << "The bars cannot make a triangle. } else { cout << "The two solutions are " << ((-b) + sqrt(discriminant)) / (2 * a ) << " and " << ((-b) . discriminant = (b * b) . b. cout << "Please enter a (0 to stop): ". cout << "Please enter a (0 to stop): ".(4 * a * c). discriminant. . while (a != 0) { cout << "Please enter b and c: ". } // end while } { // Variables double a. cin >> a. } // end if } { // Variables double a. } else { if (discriminant == 0) { cout << "The only solution is " << (-b) / (2 * a) << endl. c. if (discriminant < 0) { cout << "There are no real solutions. b.

discriminant = (b * b) . } else if (discriminant == 0) { cout << "The only solution is " << (-b) / (2 * a) << endl. } else { cout << "The two solutions are " << ((-b) + sqrt(discriminant)) / (2 * a) << " and " << ((-b) ." << endl. if (discriminant < 0) { cout << "There are no real solutions. } // end while } .sqrt(discriminant)) / (2 * a) << endl. } // end if cout << "Please enter a (0 to stop): ". cin >> a.(4 * a * c).

Sign up to vote on this title
UsefulNot useful