Read radius of a circle, calls function circleArea to calculate the area of that circle. - C++ Function

C++ examples for Function:Function Parameter

Description

Read radius of a circle, calls function circleArea to calculate the area of that circle.

Demo Code

#include <iomanip>
#include <iostream>

double circleArea(double);

const double PI = 3.14159;

int main(int argc, const char *argv[]) {
    double radius;

    std::cout << "Enter circle radius: ";
    std::cin >> radius;/*from  w  ww. ja v a  2s  .c  o m*/

    std::cout << std::fixed << std::setprecision(2)
              << "Area: " << circleArea(radius) << std::endl;
    return 0;
}
// returns the area of a circle from the given radius
double circleArea(double r) { 
   return PI * (r * r); 
}

Result


Related Tutorials