/* * Program to compute hypotenuse of a right triangle (sqrt(a*a + b*b)). * * Input: floating-point numbers a, b. * * Output: sqrt(a*a + b*b) */ #include #include /* Computes hypotenuse of right triangle with sides a and b, and returns it */ double hypotenuse(double a, double b) { /* as written in class double result; result = sqrt(a*a + b*b); return result; */ /* simpler way */ return sqrt(a*a + b*b); } /* Main program */ int main(void) { double input1; double input2; double answer; printf("enter two sides of a right triangle:\n"); scanf("%lf", &input1); /* %lf means convert to type double */ scanf("%lf", &input2); answer = hypotenuse(input1, input2); printf("hypotenuse for sides %f and %f is %f\n", input1, input2, answer); answer = hypotenuse(2*input1, 2*input2); printf("hypotenuse for sides %f and %f is %f\n", 2*input1, 2*input2, answer); return 0; }