circles2 - endl; cout << "What is the circle's...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
// Demo program for computing area and circumference of a circle // Modified to show use of the pow function of math.h #include <iostream.h> // for cin, cout #include <math.h> // for pow const double PI = 3.1415926; // ratio of circum to diam of a circle int main() { double radius; // radius of a circle, any linear units double area; // area of same circle, square units double circum; // circumference of same circle, same linear units cout << "This program computes the area and circumference of a circle." <<
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: endl; cout << "What is the circle's radius? "; // prompt for radius cin >> radius; area = PI*pow(radius, 2); // compute area using PI*r^2 circum = 2*PI*radius; // compute circumference using 2*PI*r cout << "Area:\t\t" << area << endl; // output results cout << "Circumference:\t" << circum << endl; cout << "(Circumference in same units as input; area in square units.)" << endl; return 0; }...
View Full Document

This document was uploaded on 02/10/2011.

Ask a homework question - tutors are online