Calculating the Hypotenuse: C Program for Right-Angled Triangles
Triangles are fascinating geometric shapes, especially when they are right-angled. In this blog post, we'll explore a simple C program that calculates the hypotenuse (side C) of a right-angled triangle when the lengths of sides A and B are known. Let's dive into the code:
#include <stdio.h>
#include <math.h>
int main() {
double A;
double B;
double C;
printf("Enter the length of side A: ");
scanf("%lf", &A);
printf("Enter the length of side B: ");
scanf("%lf", &B);
C = sqrt(A * A + B * B);
printf("Length of side C (hypotenuse): %.3lf", C);
return 0;
}
Copy and paste this C code into your preferred compiler, and you'll be able to calculate the hypotenuse of a right-angled triangle with ease. Understanding the relationships between the sides of a triangle is a fundamental concept in geometry, and this program simplifies the process.
Feel free to experiment with different side lengths and explore the wonders of right-angled triangles using this C program. Happy coding!