Home  >  Article  >  Backend Development  >  Program to calculate the area and perimeter of a rhombus, given what are the diagonals? In C++, what is a rhombus?

Program to calculate the area and perimeter of a rhombus, given what are the diagonals? In C++, what is a rhombus?

WBOY
WBOYforward
2023-08-31 21:13:14982browse

Program to calculate the area and perimeter of a rhombus, given what are the diagonals? In C++, what is a rhombus?

What is a rhombus?

In geometry, a rhombus is a quadrilateral with four sides of the same length. A rhombus is similar in shape to a rhombus. If the diagonals of a rhombus are at right angles, then it becomes a square.

The properties of a rhombus are-

  • The sides are equal
  • The opposite sides are parallel and the opposite angles are equal, it is a parallelogram
  • The diagonals bisect right angles

The picture below is a rhombus

Question

Given the diagonal, assume that the task of d1 and d2 is to find the rhombus The area and perimeter of a cuboid, where area is the space occupied by the shape and perimeter is the space its boundaries will cover

To calculate the area and perimeter of a cuboid, there is a formula -

Program to calculate the area and perimeter of a rhombus, given what are the diagonals? In C++, what is a rhombus?

Example

Input-: d1=6 and d2=12
Output-: The perimeter of rhombus with given diagonals are :26
   The area of rhombus with given diagonals are :36

Algorithm

Start
Step 1 -> declare function to calculate perimeter of rhombus
   int perimeter(int d1, int d2)
      Declare variable long long int perimeter
      Set perimeter = 2 * sqrt(pow(d1, 2) + pow(d2, 2))
      Print perimeter
Step 2 -> Declare function to calculate area of rhombus
   int area(int d1, int d2)
      Declare long long int area
      Set area = (d1 * d2) / 2
      Print area
Step 3 -> In main()
   Declare variable int d1 = 6, d2 = 12
   Call perimeter(d1, d2)
   Call area(d1, d2)
Stop

Example

#include <iostream>
#include <math.h>
using namespace std;
// program to calculate perimeter of rhombus
int perimeter(int d1, int d2){
   long long int perimeter;
   perimeter = 2 * sqrt(pow(d1, 2) + pow(d2, 2));
   cout<< "The perimeter of rhombus with given diagonals are :"<<perimeter;
}
//program to calculate area of rhombus
int area(int d1, int d2){
   long long int area;
   area = (d1 * d2) / 2;
   cout<<"</p><p>The area of rhombus with given diagonals are :"<< area;
}
int main(){
   int d1 = 6, d2 = 12;
   perimeter(d1, d2);
   area(d1, d2);
   return 0;
}

Output

The perimeter of rhombus with given diagonals are :26
The area of rhombus with given diagonals are :36

The above is the detailed content of Program to calculate the area and perimeter of a rhombus, given what are the diagonals? In C++, what is a rhombus?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete