w3resource

C Exercises: Check three sides of a triangle form a right triangle or not


Check if three sides form a right triangle

Write a C program to check whether the three given lengths (integers) of three sides of a triangle form a right triangle or not. Print "Yes" if the given sides form a right triangle otherwise print "No".

Input:
Integers separated by a single space.
1 <= length of the side <= 1,000

Sample Solution:

C Code:

#include<stdio.h>

int main()
{
    int x, y, z;

    // Prompt the user to input the three sides of a triangle
    printf("Input the three sides of a triangle:\n");

    // Read the input values for x, y, and z
    scanf("%d %d %d", &x, &y, &z);

    // Check if the triangle is a right angle triangle
    if ((x*x) + (y*y) == (z*z) || (x*x) + (z*z) == (y*y) || (y*y) + (z*z) == (x*x))
    {
        // If the condition is true, print that it's a right angle triangle
        printf("It is a right angle triangle!\n");
    }
    else
    {
        // If the condition is false, print that it's not a right angle triangle
        printf("It is not a right angle triangle!\n");
    }

    return 0; // End of the program
}

Sample Output:

Input the three sides of a trainagel:
12
11
13
It is not a right angle triangle!

Flowchart:

C Programming Flowchart: Check three sides of a triangle form a right triangle or not.


For more Practice: Solve these Related Problems:

  • Write a C program to check if three given integers satisfy the Pythagorean theorem and form a right triangle.
  • Write a C program to read three side lengths and determine if they can form a right triangle using squared comparisons.
  • Write a C program to implement a function that returns true if the provided sides form a right triangle.
  • Write a C program to sort three side lengths and then check if the largest squared equals the sum of squares of the other two.

Go to:


PREV : Sum two integers and count digits in the result.
NEXT : Count combinations of four digits summing to nnn.

C programming Code Editor:



Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.