CSharp · Console
// Check whether it is possible to build a triangle with the sides of length a, b, c.
// The program should input positive integers a, b, c and print “Yes” or “No” accordingly.
using System;
using System.Diagnostics;
public class Program
{
public static int InputInt(string prompt)
{
Console.Write("Enter " + prompt + ":");
return Convert.ToInt32(Console.ReadLine());
}
public static void Main()
{
// input data
int a = InputInt("length of side a");
int b = InputInt("length of side b");
int c = InputInt("length of side c");
Trace.Assert(a > 0 && b > 0 && c > 0);
// output result
if (a + b > c && a + c > b && b + c > a){
Console.Write("Yes");
}else{
Console.Write("No");
}
}
}