91.8k views
4 votes
A "Pythagorean Triple" is a set of integers which will make the sides of a right triangle when used in the calculation of Pythagoras’ Theorem. For example, "3, 4, 5" is a Pythagorean Triple. Write a short "C" function that takes three decimal integers and determines if they are a "Pythagorean Triple". The function should return a boolean which is true if the three numbers fit the pattern, and false otherwise. DO NOT write a "main()" method in this code! [15 pts.]

1 Answer

4 votes

Answer:

The function in C is as follows:

bool checkPythagoras(int a, int b, int c ){

bool chk = false;

if(a*a == b*b + c*c || b*b == a*a + c*c || c*c == b*b + a*a){

chk = true;

}

return chk;

}

Step-by-step explanation:

This defines the function. It receives three integer parameters a, b and c

bool checkPythagoras(int a, int b, int c ){

This initializes the return value to false

bool chk = false;

This checks if the three integers are Pythagorean Triple

if(a*a == b*b + c*c || b*b == a*a + c*c || c*c == b*b + a*a){

If yes, the return value is updated to true

chk = true;

}

This returns true or false

return chk;

}

User Dhanveer Thakur
by
4.3k points