Write C# Program to check whether a triangle can be formed by the given value for the angles

Write C# Program to check whether a triangle can be formed by the given value for the angles


Introduction

Write C# Program to check whether a triangle can be formed by the given value for the angles. I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability..


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. public class csharpExercise
  7. {
  8. static void Main(string[] args)
  9. {
  10.  
  11. int anglea, angleb, anglec, sum;
  12.  
  13. Console.WriteLine("Input three angles of triangle : ");
  14. anglea = Convert.ToInt32(Console.ReadLine());
  15. angleb = Convert.ToInt32(Console.ReadLine());
  16. anglec = Convert.ToInt32(Console.ReadLine());
  17.  
  18. // Calculate the sum of all angles of triangle
  19. sum = anglea + angleb + anglec;
  20.  
  21. // Check whether sum=180 then its a valid triangle otherwise invalid triangle
  22. if (sum == 180)
  23. {
  24. Console.WriteLine("It is a valid triangle.\n");
  25. }
  26. else
  27. {
  28. Console.WriteLine("It is a invalid triangle.\n");
  29. }
  30.  
  31. Console.ReadLine();
  32. }
  33. }

Result

C# language techstudy.org

     





Related Topics




Popular Posts