Example 2:    circle.cpp

//////////////////////////////////////////////////////////////
//   File: circle.cpp
//   Description: Get input value for the radius of a circle,
//   print out the circumference and area.
//   Compile:  g++  -o circle  circle.cpp
//////////////////////////////////////////////////////////////

#include<iostream>
using namespace std;

#define  PI  (3.14159)

int main(void)
{
     double radius,          // Input: radius of circle.
            area,            // Output: area of circle
            circumference;   // Output: circumference of circle

     // Get radius from user.
     cout << "Enter the circle radius: ";
     cin >> radius;

     // Compute area.
     area = PI*radius*radius;

     // Compute circumference.
     circumference = 2*PI*radius;

     // Print out area and circumference.
     cout << "The area is " << area << ", and the circumference"
          << " is " << circumference << "." << endl;

     return (0);
}
 
 
 


If you find any errors, please report them to: ptantalo@soe.ucsc.edu

webmaster@soe.ucsc.edu

Back to the SOE Class Home Pages
Back to the SOE Home Page