Answers for "how to verify if its a triangle in c"

C
1

valid triangle in c

/**
 * C program to check whether a triangle is valid or not if its sides are given
 */

#include <stdio.h>

int main()
{
    int side1, side2, side3;

    /* Input three sides of a triangle */
    printf("Enter three sides of triangle: \n");
    scanf("%d%d%d", &side1, &side2, &side3);
    
    if((side1 + side2) > side3)
    {
        if((side2 + side3) > side1)
        {
            if((side1 + side3) > side2) 
            {
                /*
                 * If side1 + side2 > side3 and
                 *    side2 + side3 > side1 and
                 *    side1 + side3 > side2 then
                 * the triangle is valid.
                 */
                printf("Triangle is valid.");
            }
            else
            {
                printf("Triangle is not valid.");
            }
        }
        else
        {
            printf("Triangle is not valid.");
        }
    }
    else
    {
        printf("Triangle is not valid.");
    }

    return 0;
}
Posted by: Guest on July-16-2021
0

how to verify if its a triangle in c

/* 
     formula is : any of 2 side is must be bigger than the third side of a triangle.
 */
#include <stdio.h>
int main()
{
     double side1, side2, side3;
     scanf("%lf %lf %lf", &side1, &side2, &side3);

     if (side1 + side2 > side3 && side2 + side3 > side1 && side1 + side3 > side2) // applying formula
     {
          printf("Yes. It can be a triangle\n");
     }
     else
     {
          printf("Yes. It can't be a triangle\n");
     }
     return 0;
}
Posted by: Guest on August-02-2021

Code answers related to "how to verify if its a triangle in c"

Code answers related to "C"

Browse Popular Code Answers by Language