Home > Backend Development > C++ > body text

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

WBOY
Release: 2023-08-31 21:13:14
forward
915 people have browsed it

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
Copy after login

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
Copy after login

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;
}
Copy after login

Output

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

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!