Home > Backend Development > C++ > In a C program, translate the following into Chinese: What is the area of ​​the largest triangle that can be embedded within a rectangle?

In a C program, translate the following into Chinese: What is the area of ​​the largest triangle that can be embedded within a rectangle?

WBOY
Release: 2023-09-01 08:21:06
forward
887 people have browsed it

Suppose a rectangle is given. We know its length L and width B. We have to find the area of ​​the largest triangle that can be inscribed within this rectangle -

In a C program, translate the following into Chinese: What is the area of ​​the largest triangle that can be embedded within a rectangle?

The largest triangle is always half the rectangle. So it will be

In a C program, translate the following into Chinese: What is the area of ​​the largest triangle that can be embedded within a rectangle?

Example

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

Output

Area : 40
Copy after login

The above is the detailed content of In a C program, translate the following into Chinese: What is the area of ​​the largest triangle that can be embedded within a rectangle?. 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