Dado uno de los Lados S , Diagonal D , o Perímetro P del cuadrado, la tarea es encontrar el área del cuadrado con el valor dado.
Ejemplos:
Entrada: S = 5
Salida: Área del cuadrado usando lado = 25Entrada: D = 4
Salida: Área del cuadrado usando diagonal = 8
Entrada: P = 32
Salida: Área del cuadrado usando perímetro = 64
Encontrar el área de un cuadrado usando su lado
El área del cuadrado de lado S está dada por:
Área = Lado * Lado
A continuación se muestra la implementación del enfoque anterior:
C++
// C++ program for the above approach #include <iostream> using namespace std; // Function to find the area of a square int areaOfSquare(int S) { // Use above formula int area = S * S; return area; } // Driver Code int main() { // Given Side of square int S = 5; // Function call cout << areaOfSquare(S); return 0; }
Java
// Java program for the above approach class GFG{ // Function to find the area of a square static int areaOfSquare(int S) { // Use above formula int area = S * S; return area; } // Driver Code public static void main(String[] args) { // Given Side of square int S = 5; // Function call System.out.println(areaOfSquare(S)); } } // This code is contributed by rock_cool
Python3
# Python3 program for the above approach # Function to find the area of a square def areaOfSquare(S): # Use above formula area = S * S return area # Driver Code if __name__ == '__main__': # Given Side of square S = 5 # Function call print(areaOfSquare(S)) # This code is contributed by Mohit Kumar
C#
// C# program for the above approach using System; class GFG{ // Function to find the area of a square static int areaOfSquare(int S) { // Use above formula int area = S * S; return area; } // Driver Code public static void Main(string[] args) { // Given Side of square int S = 5; // Function call Console.Write(areaOfSquare(S)); } } // This code is contributed by Ritik Bansal
Javascript
<script> // Javascript program for the above approach // Function to find the area of a square function areaOfSquare(S) { // Use above formula let area = S * S; return area; } // Given Side of square let S = 5; // Function call document.write(areaOfSquare(S)); // This code is contributed by divyeshrabadiya07. </script>
25
Tiempo Complejidad: O(1)
Espacio Auxiliar: O(1)
Encontrar el área de un cuadrado usando su diagonal
- El Área del cuadrado de lado dado S está dada por:
Área = S * S …(1)
- La relación entre el Lado S y la Diagonal D viene dada por:
…(2)
- Sustituyendo el valor de S de la Ecuación (2) en la Ecuación (1), tenemos:
A continuación se muestra la implementación del enfoque anterior:
C++
// C++ program for the above approach #include <iostream> using namespace std; // Function to find the area of a square int areaOfSquare(int D) { // Use above formula int area = (D * D) / 2; return area; } // Driver Code int main() { // Given diagonal of square int D = 4; // Function call cout << areaOfSquare(D); return 0; }
Java
// Java program for the above approach import java.util.*; class GFG{ // Function to find the area of a square static int areaOfSquare(int D) { // Use above formula int area = (D * D) / 2; return area; } // Driver Code public static void main(String[] args) { // Given diagonal of square int D = 4; // Function call System.out.print(areaOfSquare(D)); } } // This code is contributed by PrinciRaj1992
Python3
# Python3 program for the above approach # Function to find the area of a square def areaOfSquare(D): # Use above formula area = (D * D) // 2; return area; # Driver Code if __name__ == '__main__': # Given diagonal of square D = 4; # Function call print(areaOfSquare(D)); # This code is contributed by PrinciRaj1992
C#
// C# program for the above approach using System; class GFG{ // Function to find the area of a square static int areaOfSquare(int D) { // Use above formula int area = (D * D) / 2; return area; } // Driver Code public static void Main(String[] args) { // Given diagonal of square int D = 4; // Function call Console.Write(areaOfSquare(D)); } } // This code is contributed by amal kumar choubey
Javascript
<script> // Javascript program for the above approach // Function to find the area of a square function areaOfSquare(D) { // Use above formula let area = parseInt((D * D) / 2, 10); return area; } // Given diagonal of square let D = 4; // Function call document.write(areaOfSquare(D)); </script>
8
Tiempo Complejidad: O(1)
Espacio Auxiliar: O(1)
Encontrar el área de un cuadrado usando su perímetro
- El Área del cuadrado de lado dado S está dada por:
Área = S * S …(1)
- La relación entre el Lado S y el Perímetro P viene dada por:
PAG =4*S …(2)
- Sustituyendo el valor de S de la Ecuación (2) en la Ecuación (1), tenemos:
A continuación se muestra la implementación de la fórmula anterior:
C++
// C++ program for the above approach #include <iostream> using namespace std; // Function to find the area of a square int areaOfSquare(int P) { // Use above formula int area = (P * P) / 16; return area; } // Driver Code int main() { // Given perimeter of square int P = 32; // Function call cout << areaOfSquare(P); return 0; }
Java
// Java program for the above approach class GFG{ // Function to find the area of a square static int areaOfSquare(int P) { // Use above formula int area = (P * P) / 16; return area; } // Driver Code public static void main(String[] args) { // Given perimeter of square int P = 32; // Function call System.out.print(areaOfSquare(P)); } } // This code is contributed by amal kumar choubey
Python3
# Python3 program for the above approach # Function to find the area of a square def areaOfSquare(P): # Use above formula area = (P * P) // 16; return area; # Driver Code if __name__ == '__main__': # Given perimeter of square P = 32; # Function call print(areaOfSquare(P)); # This code is contributed by gauravrajput1
C#
// C# program for the above approach using System; class GFG{ // Function to find the area of a square static int areaOfSquare(int P) { // Use above formula int area = (P * P) / 16; return area; } // Driver Code public static void Main(String[] args) { // Given perimeter of square int P = 32; // Function call Console.Write(areaOfSquare(P)); } } // This code is contributed by amal kumar choubey
Javascript
<script> // javascript program for the above approach // Function to find the area of a square function areaOfSquare(P) { // Use above formula var area = (P * P) / 16; return area; } // Driver Code //Given perimeter of square var P = 32; // Function call document.write(areaOfSquare(P)); // This code is contributed by Princi Singh </script>
64
Tiempo Complejidad: O(1)
Espacio Auxiliar: O(1)
Publicación traducida automáticamente
Artículo escrito por shivipandey664 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA