In: Computer Science
Q6: (Sides of a Right Triangle) Write a function that reads three nonzero integers and determines whether they are the sides of a right-angled triangle. The function should take three integer arguments and return 1 (true) if the arguments comprise a right-angled triangle, and 0 (false) otherwise. Use this function in a program that inputs a series of sets of integers. Hint: a^2+b^2=C^2 Codes in C please.s
#include <stdio.h>
// Write a function that reads three nonzero integers and
// determines whether they are the sides of a right-angled triangle.
int is_right_angled(int a, int b, int c)
{
// check if sum of squares of any 2 sides equal to square of third side
if (a * a + b * b == c * c || b * b + c * c == a * a || a * a + c * c == b * b)
// return true
return 1;
// return false
return 0;
}
int main()
{
// input 3 integers.
int a, b, c;
printf("Enter 3 sides of triangle: ");
scanf("%d %d %d", &a, &b, &c);
if (is_right_angled(a, b, c))
printf("This is a right-angled triangle\n");
else
printf("This is not a right-angled triangle\n");
}
.
Output:
.