C++ examples for Function:Function Parameter
Create function to convert to polar coordinate system
#include <iostream> #include <cmath> using namespace std; void polar(double, double, double&, double&); // function prototype int main()/*w ww. java2s . c om*/ { double distance, angle; polar(3.0, 4.0, distance, angle); cout << "r = " << distance << endl; cout << "angle = " << angle << endl; return 0; } void polar(double x, double y, double& r, double& theta) { const double TODEGREES = 180.0/3.141593; r = sqrt(x * x + y * y); theta = atan(y/x) * TODEGREES; return; }