In: Computer Science
c++
1. write a c++ function that received two doubles that represent the sides of a triangle and an integer that represents the number of triangles of that size. calculate the area of all these triangles. remember area of a triangle is ahalf base times width. and return this value as a double.
If you have any questions or queries comment below. Than you.
cpp code:
#include<iostream>
using namespace std;
double area(double base, double height, int n)
{
return n*(0.5 * base * height); //calculating area of all
triangles.
}
int main()
{
/*variable declarations*/
double base, height;
int n;
/*prompting and reading the base and height*/
cout << "Enter base and height: ";
cin >> base >> height;
/*prompting and reading the number of triangles*/
cout << "Enter number of triangles: ";
cin >> n;
/*calling the function and printing the return value*/
cout << "\nArea of all these triangles: " << area(base,
height, n) << endl;
return 0;
}

Output:
