C program to find whether a triangle can be formed or not

Q. Write a C program to find whether a triangle can be formed or not.

Q. Write a C program to check the triangle is equilateral, isosceles, equilateral, scalene or right-angled triangle.

Q. Write a program to check whether a triangle is valid or not, when the three sides of the triangle are entered through the keyboard.

SOLUTION :

#include<stdio.h>
int main()
{
    float a,b,c;
    printf("\n Enter value for Side-1 : ");
    scanf("%f",&a);
    printf("\n Enter value for Side-2 : ");
    scanf("%f",&b);
    printf("\n Enter value for Side-3 : ");
    scanf("%f",&c);

    if(a<(b+c)&&b<(a+c)&&c<(a+b))
    {
        printf("\n RESULT: It is a Triangle.");
        if(a==b&&a==c&&b==c)
        printf("\n It is a Equilateral Triangle.");
        else if(a==b||a==c||b==c)
        printf("\n It is a Isosceles Triangle.");
        else if((a*a)==(b*b)+(c*c)||(b*b)==(a*a)+(c*c)||(c*c)==(a*a)+(b*b))
        printf("\n It is a Right-angle Triangle.");
        else if(a!=b&&a!=c&&b!=c)
        printf("\n It is a Scalene Triangle.");
    }
    else
    printf("\n RESULT: This Triangle is NOT possible.");
    getch ();
    return 0;
}

OUTPUT OF SOLUTION :

scalene triangle

equilateral triangle

triangle not possible

isoceles triangle

right angled trinagle

Advertisements

5 responses to “C program to find whether a triangle can be formed or not

  1. Hey!!! Can u give me a program that detects impossible entries for sides of triangle like 0 or negative values??

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s