Home  >  Article  >  Backend Development  >  Program to find the perimeter of a rhombus using diagonals

Program to find the perimeter of a rhombus using diagonals

WBOY
WBOYforward
2023-08-27 15:05:09945browse

A rhombus is a simple quadrilateral with all four sides having the same length. The perimeter of a rhombus can be found in two ways.

  1. Add all edges.
  2. Using diagonals

A quadrilateral has two diagonals. The area and perimeter of the quadrilateral can be found based on the length of the diagonals.

Using the diagonal of the rhombus to find the perimeter of the rhombus is 2{√(d1)2 (d2)2 }

Program to find the perimeter of a rhombus using diagonals

Logic - Use the diagonals of a rhombus to find its perimeter. You need the formula 2{√(d1)2 (d2)2 } In your code you need to use a math class that supports squareRoot and the squaring of numbers.

The following code shows a program to find the perimeter of a rhombus using its diagonals.

Example

#include <stdio.h>
#include <math.h>
int main(){
   int d1 = 3, d2= 4, perimeter;
   perimeter = (2 * sqrt(pow(d1,2)+pow(d2,2)));
   printf("perimeter is %d", perimeter);
   return 0;
}

Output

perimeter is 10

The above is the detailed content of Program to find the perimeter of a rhombus using diagonals. 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