Coding Practice

Write a C program to input all sides of a triangle and check whether triangle is valid or not

Valid Triangle Check by Sides
Sample Output
Enter three sides...
6
5
7
Triangle is valid.

Process returned 0 (0x0)   execution time : 10.850 s
Press any key to continue.
Source Code
#include<stdio.h>
 
int main()
{
    int side1, side2, side3;
 
    printf("Enter three sides...\n");
    scanf("%d %d %d", &side1, &side2, &side3);
 
    if(side1 + side2 > side3 && side1 + side3 > side2 && side2 + side3 > side1)
    {
        printf("Triangle is valid.\n");
    }
    else
    {
        printf("Triangle is not valid.\n");
    }
    return 0;
}
Sample Output
Enter three sides...
2
3
5
Triangle is not valid.

Process returned 0 (0x0)   execution time : 3.128 s
Press any key to continue.

No comments:

Post a Comment

Change Theme
X