Program to Check if Triangle is Valid or Not using Angles

Program to Check if Triangle is Valid or Not using Angles

  • Write a program to check if Triangle is Valid or Not using Angles in C
  • Write a program to check if Triangle is Valid or Not using Angles in C++
  • Write a program to check if Triangle is Valid or Not using Angles in Python
  • Write a program to check if Triangle is Valid or Not using Angles in PHP
  • Write a program to check if Triangle is Valid or Not using Angles in Java
  • Write a program to check if Triangle is Valid or Not using Angles in Java Script
  • Write a program to check if Triangle is Valid or Not using Angles in C#

Explanation:

To determine if a triangle is valid using its angles, you can use the following criteria:

Triangle Validity Criteria (Based on Angles)

  1. The sum of the three angles of a triangle must be exactly 180 degrees.
  2. Each angle must be greater than 0 degrees (no angle can be zero or negative).

Logic to Check Validity

  • Input the three angles of the triangle: angle1, angle2, angle3.
  • If the sum of the angles is 180 degrees and all angles are greater than 0, then the triangle is valid.
  • Otherwise, the triangle is invalid.

Program to Check if Triangle is Valid or Not using Angles

#include <stdio.h>

int main() {
    int angle1, angle2, angle3;
    printf("Enter the three angles of the triangle: ");
    scanf("%d %d %d", &angle1, &angle2, &angle3);

    if (angle1 + angle2 + angle3 == 180) {
        printf("The triangle is valid.\n");
    } else {
        printf("The triangle is not valid.\n");
    }

    return 0;
}

#include <iostream>
using namespace std;

int main() {
    int angle1, angle2, angle3;
    cout << "Enter the three angles of the triangle: ";
    cin >> angle1 >> angle2 >> angle3;

    if (angle1 + angle2 + angle3 == 180) {
        cout << "The triangle is valid." << endl;
    } else {
        cout << "The triangle is not valid." << endl;
    }

    return 0;
}

angle1 = int(input("Enter the first angle of the triangle: "))
angle2 = int(input("Enter the second angle of the triangle: "))
angle3 = int(input("Enter the third angle of the triangle: "))

if angle1 + angle2 + angle3 == 180:
    print("The triangle is valid.")
else:
    print("The triangle is not valid.")

<?php
$angle1 = readline("Enter the first angle of the triangle: ");
$angle2 = readline("Enter the second angle of the triangle: ");
$angle3 = readline("Enter the third angle of the triangle: ");

if ($angle1 + $angle2 + $angle3 == 180) {
    echo "The triangle is valid.\n";
} else {
    echo "The triangle is not valid.\n";
}
?>

import java.util.Scanner;

public class TriangleValidity {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter the first angle of the triangle: ");
        int angle1 = scanner.nextInt();
        System.out.print("Enter the second angle of the triangle: ");
        int angle2 = scanner.nextInt();
        System.out.print("Enter the third angle of the triangle: ");
        int angle3 = scanner.nextInt();

        if (angle1 + angle2 + angle3 == 180) {
            System.out.println("The triangle is valid.");
        } else {
            System.out.println("The triangle is not valid.");
        }

        scanner.close();
    }
}

let angle1 = parseInt(prompt("Enter the first angle of the triangle:"));
let angle2 = parseInt(prompt("Enter the second angle of the triangle:"));
let angle3 = parseInt(prompt("Enter the third angle of the triangle:"));

if (angle1 + angle2 + angle3 === 180) {
    console.log("The triangle is valid.");
} else {
    console.log("The triangle is not valid.");
}

using System;

class Program {
    static void Main() {
        Console.Write("Enter the first angle of the triangle: ");
        int angle1 = Convert.ToInt32(Console.ReadLine());

        Console.Write("Enter the second angle of the triangle: ");
        int angle2 = Convert.ToInt32(Console.ReadLine());

        Console.Write("Enter the third angle of the triangle: ");
        int angle3 = Convert.ToInt32(Console.ReadLine());

        if (angle1 + angle2 + angle3 == 180) {
            Console.WriteLine("The triangle is valid.");
        } else {
            Console.WriteLine("The triangle is not valid.");
        }
    }
}

List of All Programs