c check if is a right triangle
#include <stdio.h>
int isRightTriangle(int a, int b, int c) {
if (aa + bb == cc || aa + cc == bb || bb + cc == a*a) {
return 1;
} else {
return 0;
}
}
int main() {
int side1, side2, side3;
printf("Enter the lengths of three sides of a triangle: ");
scanf("%d %d %d", &side1, &side2, &side3);
if (isRightTriangle(side1, side2, side3)) {
printf("It is a right triangle.\n");
} else {
printf("It is not a right triangle.\n");
}
return 0;
}
Explanation:
- The program defines a function isRightTriangle
that takes three integers as input representing the lengths of the sides of a triangle.
- Inside the function, it checks if any of the three conditions for a right triangle are satisfied:
- aa + bb == c*c
: The sum of the squares of the two shorter sides is equal to the square of the longest side.
- aa + cc == b*b
: The sum of the squares of the two shorter sides is equal to the square of the longest side.
- bb + cc == a*a
: The sum of the squares of the two shorter sides is equal to the square of the longest side.
- If any of these conditions are true, the function returns 1, indicating that it is a right triangle. Otherwise, it returns 0.
- In the main
function, the program prompts the user to enter the lengths of three sides of a triangle.
- It then calls the isRightTriangle
function with the input values and checks the return value.
- If the return value is 1, it prints "It is a right triangle." Otherwise, it prints "It is not a right triangle."
Note: The code assumes that the input values are positive integers. It does not handle negative values or zero values for the sides of the triangle.