Home  >  Article  >  Backend Development  >  Is it possible to write a function in C program that calculates the area of ​​the largest possible rhombus that can be inscribed within a rectangle?

Is it possible to write a function in C program that calculates the area of ​​the largest possible rhombus that can be inscribed within a rectangle?

王林
王林forward
2023-08-27 16:21:03562browse

Here we will see a problem where a rectangle is given. We must find the area of ​​the largest rhombus that can be inscribed in a rectangle. The figure is as follows -

Is it possible to write a function in C program that calculates the area of ​​the largest possible rhombus that can be inscribed within a rectangle?

The length of the rectangle is "l" and the width is "b", so the area of ​​the rhombus is-

Source code

#include <iostream>
#include <cmath>
using namespace std;
float area(float l, float b) {
   if (l < 0 || b < 0) //if the values are negative it is invalid
      return -1;
   float area = (l*b) /2;
   return area;
}
int main() {
   float l = 20.0, b = 7;
   cout << "Area : " << area(l, b);
}

Output

Area : 70

The above is the detailed content of Is it possible to write a function in C program that calculates the area of ​​the largest possible rhombus that can be inscribed within a rectangle?. 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
Previous article:Array in C languageNext article:Array in C language