Triangle validation in C


In this, we are going to write a simple program to check if a triangle is valid or not with help of the C programming language.


#include <stdio.h>

void main()
{
    double a, b, c;
    printf("Enter sides of triangle\n");
    printf("Enter value of Side a\n");
    scanf("%lf", &a);
    printf("Enter value of Side b\n");
    scanf("%lf", &b);
    printf("Enter value of Side c\n");
    scanf("%lf", &c);

    // sum of two sides must be strictly greater than third side
    // Eg   3,4,5 or 2,5,6--- valid triangle
    //      1,2,3 or 1,11,10 --- not valid triangle

    if ((a + b) <= c || (a + c) <= b || (b + c) <= c)
    {
        printf("NOT a valid triangle");
    }
    else
    {
        printf("VALID triangle");
    }
}

#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post