Thu Nov 13, 2008 2:16 pm
#include <iostream>
using namespace std;
// Swap two values.
void swap(double &a, double &b)
{
double tmp = a;
a = b;
b = tmp;
}
// Return multiple results.
void stats(double x, double y, double &absdif, double &mean, double &sumsqr)
{
if(x > y) swap(x, y);
absdif = y - x;
mean = (x + y) / 2.0;
sumsqr = x*x + y*y;
}
int main()
{
double a = 10.45;
double b = 20.22;
cout << a << " " << b << endl;
swap(a, b);
cout << a << " " << b << "\n" << endl;
double c = 4.56;
double d = -3.45;
double absdif, mean, ss;
stats(c, d, absdif, mean, ss);
cout << c << " " << d << " " << absdif << " " <<
mean << " " << ss << endl;
stats(22.0, 41.5, absdif, mean, ss);
cout << absdif << " " << mean << " " << ss << endl;
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.