User Tools


#include <iostream>
#include <math.h>

using namespace std;

double length_of_hypoteneuse(double a, double b) {
        //a and b are modified in the following two lines...
        a *= a;
        b *= b;
        double c = sqrt(a + b);
        return c;
}

main() {
        double length1 = 3;
        double length2 = 4;
        cout << "Lengths before call: " << length1 << " , " << length2 << endl;
        //But unmodified after the following call...
        double hypoteneuse = length_of_hypoteneuse(length1,length2);
        cout << "Length of hypoteneuse: " << hypoteneuse << endl;
        cout << "Lengths after call: " << length1 << " , " << length2 << endl;
}


Top