C# Function to test for a valid triangle.

/* C# Function to test for a valid triangle. */
using System;
public class Demo
{
    public static int IsTriangle(int a, int b, int c)
    {
        int chk;
        if(a + b > c & a + c > b & b + c > a)
            chk = 1;
        else
            chk = 0;
        return chk;
    }

    public static void Main(string[] args)
    {
        int a, b, c, find;
        Console.WriteLine("Enter 3 side of triangle A B C : \n");
        a = Convert.ToInt32(Console.ReadLine());
        b = Convert.ToInt32(Console.ReadLine());
        c = Convert.ToInt32(Console.ReadLine());
        find = IsTriangle(a, b, c);
        if(find == 1)
            Console.WriteLine("\nValid triangle ");
        else
            Console.WriteLine("\nInvalid triangle ");
        Console.ReadLine();
    }
}

Output :
Enter 3 side of triangle A B C :
5
6
6

Valid triangle



Leave a comment