问题:
- Define a function 'hypotenuse' that calculates the length of the hypotenuse of a right triangle when the other two sides are given
- The function should take two argument of type double and return the typotenuse as a double (with 1 digit after the decimal point)
要求效果如下:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
/*求直角三角形的斜边 hypotenuse*/
double a;
double b;
double hypotenuse(double a, double b);
int main(void) {
while (1) {
printf("Enter the sides of the triangle:");
scanf_s("%lf %lf", &a, &b);
printf("Hypotenuse: %.1lf\n", hypotenuse(a,b));
}
system("pause");
return 0;
}
double hypotenuse(double a, double b) {
return sqrt(pow(a, 2) + pow(b, 2));
}