183k views
2 votes
create a simple f unction that uses pythagorean theorem to calculate the hypotenuse of a right triangle, by using 2 arguments (of x and y respectively) as the inputs, i.e., when call the f unction in the command window, you need to input values of both x and y. note that both x

1 Answer

1 vote

#include <bits/stdc++.h>

int calc_hypo(int idx, int idy) {

return (idx>0 && idy>0) ? sqrt(pow(idx,2)+pow(idy,2)) : 0;

}

int main(int argc, char* argv[]) {

//Get input from user.

int x,y;

std::cin >> x >> y;

//Return the result.

std::cout << "The result is " << calc_hypo(x,y) << std::endl;

return 0;

}

create a simple f unction that uses pythagorean theorem to calculate the hypotenuse-example-1
User Tonicbupt
by
4.7k points