📜  广场面积|使用侧面,对角线和周长

📅  最后修改于: 2021-04-24 03:23:53             🧑  作者: Mango

给定正方形的边S ,对角D或周长P之一,任务是找到具有给定值的正方形面积。

例子:

用边寻找方的面积

S边的正方形的面积由下式给出:

下面是上述方法的实现:

C++
// C++ program for the above approach
#include 
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


C++
// C++ program for the above approach
#include 
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


C++
// C++ program for the above approach
#include 
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


输出:
25

使用对角线找到正方形的区域

  • 给定边S的正方形的面积由下式给出:
  • S边与对角线D之间的关系由下式给出:
  • 用公式(1)中的公式(2)代替S的值,我们得到:

下面是上述方法的实现:

C++

// C++ program for the above approach
#include 
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

Java脚本


输出:
8

使用正方形的周长查找正方形的面积

  • 给定边S的正方形的面积由下式给出:
  • S与周长P之间的关系由下式给出:
  • 用公式(1)中的公式(2)代替S的值,我们得到:

下面是上述公式的实现:

C++

// C++ program for the above approach
#include 
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

Java脚本


输出:
64