/************************************************************************ *
The following is a simple C++ program containing
declarations, expressions, statements, and two functions:
* ************************************************************************/
/**
** A simple C++ program containing declarations,
** expressions, statements, and two functions:
**/
#include <math.h> // contains definition of abs()
double multiplier, common_ratio; // variable declarations
double geo_series(double a, double r) // function definition
{
if (r == 1) // if statement
return -1.0; // return statement
else if (abs(r) < 1.0) // else if statement
return (a / (1 - r)); // statement containing
// expression
else return -2.0;
}
void main() // program execution begins here
{
double sum; // variable declaration
multiplier = 2.2; // initialization of external variable
common_ratio = 3.1; // initialization of external variable
sum = geo_series(multiplier, common_ratio); // function call
// ..
}