![]() |
In this article, we will discuss how to find out whether the given angles create a valid triangle or not. Here we will take input from the user and, based on the input, we will check whether the angles are equal, less than, or greater than 180 degrees and print the desired result. ExampleInputs : 80 60 40 Output : Valid Triangle Inputs : 55 44 30 Output : Invalid Triangle A triangle is valid if the sum of all its angles is equal to 180 degrees. Steps
# Taking input from user echo "Enter the angles of triangle" read A1 read A2 read A3 # storing the sum of angles in sum variable sum=$((A1+A2+A3)) # checking if sum is equal to 180 if [ $sum -eq 180 ] # if condition is satisfied then echo "Valid triangle" # if condition is not satisfied else echo "Invalid triangle" # end of if loop fi Output: ![]() output Time complexity: O(1) as constant operations are done Auxiliary space: O(1) |
Reffered: https://www.geeksforgeeks.org
Linux Unix |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |