Write a C program to check whether a triangle is Equilateral, Isosceles or Scalene. Equilateral triangle: An equilateral triangle is a triangle in which all three sides are equal. In the familiar Euclidean geometry, equilateral triangles are also equiangular; that is, all three internal angles are also congruent to each other and are each 60°. Isosceles triangle: An isosceles triangle is a triangle that has two sides of equal length. Scalene triangle: A scalene triangle is a triangle that has three unequal sides, such as those illustrated above. Pictorial Presentation: Sample Solution: C Code: Sample Output: Flowchart: C Programming Code Editor: Improve this sample solution and post your code through Disqus. Previous: Write a C program to read temperature in centigrade and display a suitable message according to temperature state below.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
Maximum value of int: In C: #include <limits.h> then use int imin = INT_MIN; // minimum value int imax = INT_MAX;or #include <float.h> float fmin = FLT_MIN; // minimum positive value double dmin = DBL_MIN; // minimum positive value float fmax = FLT_MAX; double dmax = DBL_MAX;Ref : https://bit.ly/3fi8yk9
I am trying to write java program to see if a triangle is scalene, isosceles, equilateral or not a triangle. With the integers I used it is supposed to be not a triangle (1, 1, 30). But I keep getting scalene and not a triangle together. Any help is appreciated! Thank you! public class Tri { static void checkTriangle(int x, int y, int z) { // Check for equilateral triangle if (x == y && y == z ) System.out.println("Equilateral Triangle"); // Check for isoceles triangle else if (x == y || y == z || z == x ) System.out.println("Isoceles Triangle"); // Check for scalene triangle else if (x != y || y!= z || z != x) System.out.println("Scalene Triangle"); { // Check for not a triangle if (x + y < z || x + z < y || y + z > x) System.out.println("Not a triangle"); } } public static void main(String[] args) { { int x = 1, y = 1, z = 30; checkTriangle(x, y, z); } } }Given the sides of a triangle, write a program to check whether the triangle is equilateral, isosceles or scalene and find its area. import java.util.Scanner; class Triangle { public static void main(String args[]) { // Scanner class object to read input values Scanner sc = new Scanner(System.in); // declare variables int a, b, c; double p, area; // read sides of trangle from user System.out.print("Enter 3 sides : "); a = sc.nextInt(); b = sc.nextInt(); c = sc.nextInt(); //check is sides can form a triangle if ((a < b + c) && (b < a + c) && (c < a + b)) { // equilateral triangle if all sides are equal if ((a == b) && (b == c)) System.out.println("Equilateral triangle"); // isosceles triangle if any two sides are equal else if ((a == b) || (b == c) || (c == a)) System.out.println("Isosceles triangle"); // scalene triangle if no sides are equal else System.out.println("Scalene triangle"); // find area p = (a + b + c) / 2; area = Math.sqrt(p * (p - a) * (p - b) * (p - c)); // display area System.out.println("Area of triangle is = " + area); } else { System.out.println("Cannot form a triangle"); } } }Enter 3 sides : 3 4 5 Scalene triangle Area of triangle is = 6.0
Write a program to input the three sides of a triangle and check whether it forms a triangle or not, if it forms a triangle, check whether it is an equilateral, isosceles or a scalene triangle. (Hint: To form a triangle, each side should be less the sum of the other two sides. To form an equilateral triangle every side should be equal. To form an isosceles triangle any two sides should be equal. To form a scalene triangle all three sides should be different from each other.)
Given three integers as X, Y, and Z representing the three sides of a triangle, the task is to check whether the triangle formed by the given sides is equilateral, isosceles, or scalene.
Examples:
Approach: Follow the steps below to solve the problem:
Below is the implementation of the above approach:
Time Complexity: O(1) Article Tags : Practice Tags : |