C# Sharp Exercises: Check whether a triangle can be formed by given value
C# Sharp Conditional Statement: Exercise-15 with Solution
Write a C# Sharp program to check whether a triangle can be formed by the given value for the angles.
Sample Solution:-
C# Sharp Code:
using System;
public class Exercise15
{
public static void Main()
{
int anga, angb, angc, sum; //are three angles of a triangle
Console.Write("\n\n");
Console.Write("Check whether a triangle can be formed by given value:\n");
Console.Write("--------------------------------------------------------");
Console.Write("\n\n");
Console.Write("Input angle1 of triangle: ");
anga= Convert.ToInt32(Console.ReadLine());
Console.Write("Input angle 2 of triangle: ");
angb= Convert.ToInt32(Console.ReadLine());
Console.Write("Input angle 3 of triangle: ");
angc= Convert.ToInt32(Console.ReadLine());
/* Calculate the sum of all angles of triangle */
sum = anga + angb + angc;
/* Check whether sum=180 then its a valid triangle otherwise not */
if(sum == 180)
{
Console.Write("The triangle is valid.\n");
}
else
{
Console.Write("The triangle is not valid.\n");
}
}
}
Sample Output:
Check whether a triangle can be formed by given value: -------------------------------------------------------- Input angle1 of triangle: 90 Input angle 2 of triangle: 45 Input angle 3 of triangle: 45 The triangle is valid.
Pictorial Presentation:
Flowchart:
C# Sharp Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a C# Sharp program to check whether a triangle is Equilateral, Isosceles or Scalene.
Next: Write a C# Sharp program to check whether an alphabet is a vowel or consonant.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework