Table of Contents
The program to identify a quadrilateral read inputs – length of sides and angles made by the quadrilateral shape and prints the shape name as output.
Before you practice this program, you must go through the concepts of quadrilateral shapes and their differences. See the next section.
Problem Definition
A quadrilateral is a polygon shape that has \Large 4 sides and corners that make \Large 4 angles. The sum of those angles must be equal to \Large 360 \hspace{4px} degrees. There are many types of quadrilateral shapes, you will find a brief description of each shape below.
Square
A square has \Large 4 equal sides and \Large 4 right angles at each corner.

Rectangle
A rectangle has \Large 4 sides with parallel sides are of the same length and \Large 4 corners are right angles. The rectangle has a longer side and a shorter side.

Rhombus
A rhombus is like a square or diamond with \Large 4 equal sides, but none of the corners is a right angle.

Parallelogram
Any quadrilateral that has two pair of parallel sides is a parallelogram. There are shapes which demonstrate properties of parallelogram – square, rectangle, and a rhombus are special case of a parallelogram.
In general, parallelogram has:
- Opposite sides are parallel
- Opposite sides are equal
- Opposite angles are equal

Trapezoid
If a quadrilateral contains at least one pair of parallel lines then it is called a trapezoid.

Kite
A kite is a quadrilateral that has a pair of adjacent sides of equal length and the angle where these two pair meet are equal.

Flowchart

Program Codes – Program to Identify Quadrilateral
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
float side[4], angle[4];
float sum = 0;
int i, right = 0, equal = 0;
printf("Enter 4 sides:\n");
for (i = 0; i < 4; i++)
scanf("%f", &side[i]);
printf("Enter 4 angles:\n");
for (i = 0; i < 4; i++)
{
scanf("%f", &angle[i]);
sum += angle[i];
if (fabs(angle[i] - 90) < 0.001)
right++;
}
if (fabs(sum - 360) > 0.001)
{
printf("Invalid quadrilateral\n");
return 0;
}
for (i = 1; i < 4; i++)
if (fabs(side[i] - side[0]) < 0.001)
equal++;
if (equal == 3 && right == 4)
printf("Square\n");
else if (right == 4 && side[0] == side[2] && side[1] == side[3])
printf("Rectangle\n");
else if (equal == 3)
printf("Rhombus\n");
else if (side[0] == side[2] || side[1] == side[3])
printf("Parallelogram\n");
else
printf("Trapezoid\n");
return 0;
}
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
float side[4], angle[4], sum = 0;
int right = 0, equal = 0;
cout << "Enter 4 sides:\n";
for (int i = 0; i < 4; i++)
cin >> side[i];
cout << "Enter 4 angles:\n";
for (int i = 0; i < 4; i++)
{
cin >> angle[i];
sum += angle[i];
if (fabs(angle[i] - 90) < 0.001)
right++;
}
if (fabs(sum - 360) > 0.001)
{
cout << "Invalid quadrilateral\n";
return 0;
}
for (int i = 1; i < 4; i++)
if (fabs(side[i] - side[0]) < 0.001)
equal++;
if (equal == 3 && right == 4)
cout << "Square\n";
else if (right == 4 && side[0] == side[2] && side[1] == side[3])
cout << "Rectangle\n";
else if (equal == 3)
cout << "Rhombus\n";
else if (side[0] == side[2] || side[1] == side[3])
cout << "Parallelogram\n";
else
cout << "Trapezoid\n";
return 0;
}import java.util.Scanner;
class Quadrilateral {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
float[] side = new float[4];
float[] angle = new float[4];
float sum = 0;
int right = 0, equal = 0;
System.out.println("Enter 4 sides:");
for (int i = 0; i < 4; i++)
side[i] = sc.nextFloat();
System.out.println("Enter 4 angles:");
for (int i = 0; i < 4; i++) {
angle[i] = sc.nextFloat();
sum += angle[i];
if (Math.abs(angle[i] - 90) < 0.001)
right++;
}
if (Math.abs(sum - 360) > 0.001) {
System.out.println("Invalid quadrilateral");
return;
}
for (int i = 1; i < 4; i++)
if (Math.abs(side[i] - side[0]) < 0.001)
equal++;
if (equal == 3 && right == 4)
System.out.println("Square");
else if (right == 4 && side[0] == side[2] && side[1] == side[3])
System.out.println("Rectangle");
else if (equal == 3)
System.out.println("Rhombus");
else if (side[0] == side[2] || side[1] == side[3])
System.out.println("Parallelogram");
else
System.out.println("Trapezoid");
sc.close();
}
}side = []
angle = []
sum_angle = 0
right = equal = 0
print("Enter 4 sides:")
for _ in range(4):
side.append(float(input()))
print("Enter 4 angles:")
for _ in range(4):
a = float(input())
angle.append(a)
sum_angle += a
if abs(a - 90) < 0.001:
right += 1
if abs(sum_angle - 360) > 0.001:
print("Invalid quadrilateral")
exit()
for i in range(1, 4):
if abs(side[i] - side[0]) < 0.001:
equal += 1
if equal == 3 and right == 4:
print("Square")
elif right == 4 and side[0] == side[2] and side[1] == side[3]:
print("Rectangle")
elif equal == 3:
print("Rhombus")
elif side[0] == side[2] or side[1] == side[3]:
print("Parallelogram")
else:
print("Trapezoid")
Output
Enter 4 sides:
20
20
20
20
Enter 4 angles:
90
90
90
90
Square
Enter 4 sides:
12
24
12
24
Enter 4 angles:
60
120
60
120
Parallelogram