Q. Accept three sides of triangle as input, and print whether the triangle is valid or not
Program
#include <stdio.h>
int main()
{
int side1, side2, side3;
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)
{
printf("Triangle is valid.");
}
else
{
printf("Triangle is not valid.");
}
}
else
{
printf("Triangle is not valid.");
}
}
else
{
printf("Triangle is not valid.");
}
}
Output:
Enter three sides of triangle:
4 6 7
Triangle is valid.
Program
#include <stdio.h>
int main()
{
int side1, side2, side3;
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)
{
printf("Triangle is valid.");
}
else
{
printf("Triangle is not valid.");
}
}
else
{
printf("Triangle is not valid.");
}
}
else
{
printf("Triangle is not valid.");
}
}
Output:
Enter three sides of triangle:
4 6 7
Triangle is valid.
0 Comments