previous | start | next

Example 2



    1   // File: area.cpp
    2   // Description: Compute the area of some circles
    3   // Author: 
    4   // Created: 07 Sep 05
    5   
    6   #include <iostream>
    7   
    8   using namespace std;
    9   
   10   int main()
   11   {
   12     const double pi = 3.1415926535897932384626433832795;
   13     double r1 = 1.0, r2 = 1.5;
   14     double a1, a2;
   15   
   16     a1 = pi * r1 * r1;
   17     a2 = pi * r2 * r2;
   18   
   19     cout.precision(3);
   20     cout.setf(ios::fixed);
   21     cout.setf(ios::showpoint);
   22   
   23     cout << "A circle of radius " << r1 << " has area " << a1 << endl;
   24     cout << "A circle of radius " << r2 << " has area " << a2 << endl;
   25   
   26   
   27     return 0;
   28   }
   29   
   30     

Output:

A circle of radius 1.000 has area 3.142
A circle of radius 1.500 has area 7.069



previous | start | next