Dados cuatro enteros A , B , C y D que representan los cuatro ángulos de un cuadrilátero en grados. La tarea es verificar si el cuadrilátero dado es válido o no.
Ejemplos:
Entrada: A = 80, B = 70, C = 100, D=110
Salida: VálidoEntrada: A = 70, B = 80, C = 130, D=60
Salida: Inválido
Planteamiento:
Un cuadrilátero es válido si la suma de los cuatro ángulos es igual a 360 grados.
A continuación se muestra la implementación del enfoque anterior:
C++
// C++ program to check if a given // quadrilateral is valid or not #include <bits/stdc++.h> using namespace std; // Function to check if a given // quadrilateral is valid or not bool Valid(int a, int b, int c, int d) { // Check condition if (a + b + c + d == 360) return true; return false; } // Driver code int main() { int a = 80, b = 70, c = 100, d = 110; if (Valid(a, b, c, d)) cout << "Valid quadrilateral"; else cout << "Invalid quadrilateral"; return 0; }
Java
// Java program to check if a given // quadrilateral is valid or not class GFG { // Function to check if a given // quadrilateral is valid or not public static int Valid(int a, int b, int c, int d) { // Check condition if (a + b + c + d == 360) return 1; return 0; } // Driver code public static void main (String[] args) { int a = 80, b = 70, c = 100, d = 110; if (Valid(a, b, c, d) == 1) System.out.println("Valid quadrilateral"); else System.out.println("Invalid quadrilateral"); } } // This code is contributed // by apurva_sharma244
Python3
# Python program to check if a given # quadrilateral is valid or not # Function to check if a given # quadrilateral is valid or not def Valid(a, b, c, d): # Check condition if (a + b + c + d == 360): return True; return False; # Driver code a = 80; b = 70; c = 100; d = 110; if (Valid(a, b, c, d)): print("Valid quadrilateral"); else: print("Invalid quadrilateral"); # This code is contributed by Rajput-Ji
C#
// C# program to check if a given // quadrilateral is valid or not class GFG { // Function to check if a given // quadrilateral is valid or not static bool Valid(int a, int b, int c, int d) { // Check condition if (a + b + c + d == 360) return true; return false; } // Driver code public static void Main() { int a = 80, b = 70, c = 100, d = 110; if (Valid(a, b, c, d)) Console.WriteLine("Valid quadrilateral"); else Console.WriteLine("Invalid quadrilateral"); } } // This code is contributed by nidhiva
PHP
<?php // PHP program to check if a given // quadrilateral is valid or not // Function to check if a given // quadrilateral is valid or not function Valid($a, $b, $c, $d) { // Check condition if ($a + $b + $c + $d == 360) return true; return false; } // Driver Code $a = 80; $b = 70; $c = 100; $d = 110; if (Valid($a, $b, $c, $d)) echo("Valid quadrilateral"); else echo("Invalid quadrilateral"); // This code is contributed by Naman_garg. ?>
Javascript
<script> // Javascript program to check if a given // quadrilateral is valid or not // Function to check if a given // quadrilateral is valid or not function Valid(a, b, c, d) { // Check condition if (a + b + c + d == 360) return 1; return 0; } // Driver code var a = 80, b = 70, c = 100, d = 110; if (Valid(a, b, c, d) == 1) document.write("Valid quadrilateral"); else document.write("Invalid quadrilateral"); // This code is contributed by Khushboogoyal499 </script>
Producción
Valid quadrilateral
Complejidad de tiempo : O(1)
Espacio Auxiliar: O(1)
Publicación traducida automáticamente
Artículo escrito por apurva_sharma244 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA