• Language

    C

  • Description

    Write an algorithm for a program which inputs the lengths a b and c of the three sides of a triangle. The program determines whether the triangle is right angled and prints out a message to say whether or not the triangle is right angled. You may assume that a is the longest side. The triangle is right angled if a squared = b squared + c squared.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <stdio.h>
#include <stdlib.h>

int main (void)
{
    float side_a, side_b, side_c;
    printf ("Enter the value of side a: ");
    scanf ("%f", &side_a);
    (void) getchar ();
    printf ("Enter the value of side b: ");
    scanf ("%f", &side_b);
    (void) getchar ();
    printf ("Enter the value of side c: ");
    scanf ("%f", &side_c);
    (void) getchar ();
    if(side_a*side_a==side_b*side_b+side_c*side_c)
        printf ("The triangle is right angled.\n");
    else
        printf ("The triangle is not right angled.\n");
    putchar ('\n');
    system ("pause");
    return EXIT_SUCCESS;
}