circles - endl; cout <<...

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 #include <iostream> using namespace std; 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 &lt;&lt; &quot;What is the radius of the circle? &quot;; // prompt for radius cin &gt;&gt; radius; area = PI*radius*radius; // compute area using PI*r^2 circum = 2*PI*radius; // compute circumference using 2*PI*r cout &lt;&lt; &quot;Area:\t\t&quot; &lt;&lt; area &lt;&lt; endl; // output results cout &lt;&lt; &quot;Circumference:\t&quot; &lt;&lt; circum &lt;&lt; endl; cout &lt;&lt; &quot;(Circumference in same units as input; area in square units.)&quot; &lt;&lt; endl; return 0; }...
View Full Document

Ask a homework question - tutors are online