计算已知对角线的菱形面积和周长的程序
C++ 中的菱形是什么?
什么是菱形?
在几何学中,菱形是具有四条等长边的四边形。菱形的形状类似于钻石。如果菱形的对角线成直角相交,则它成为正方形。
菱形的特性包括:
- 等边
- 对边平行且对角相等,使其成为平行四边形
- 对角线互相垂直平分
以下是菱形的图形

问题
给定对角线,例如 d1 和 d2,任务是找到菱形的面积和周长,其中面积是形状占据的空间,周长是其边界将覆盖的空间。
计算长方体的面积和周长,可以使用以下公式:

示例
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
算法
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
示例
#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<<"
The area of rhombus with given diagonals are :"<< area;
}
int main(){
int d1 = 6, d2 = 12;
perimeter(d1, d2);
area(d1, d2);
return 0;
}输出
The perimeter of rhombus with given diagonals are :26 The area of rhombus with given diagonals are :36
广告
数据结构
网络
关系数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP