Computer Science, asked by abu61667, 10 months ago

write a program to find area of a triangle.​

Answers

Answered by krati1001
1

Explanation:

1. int main() { double a, b, c, s, area;

2. printf("Enter sides of a triangle\n"); scanf("%lf%lf%lf", &a, &b, &c);

3. s = (a+b+c)/2; // Semiperimeter.

area = sqrt(s*(s-a)*(s-b)*(s-c));

4. printf("Area of the triangle = %.2lf\n", area).

Answered by eenishika
2

Answer:

// C++ Program to find the area

// of triangle

#include <bits/stdc++.h>

using namespace std;

float findArea(float a, float b, float c)

{

// Length of sides must be positive

// and sum of any two sides

// must be smaller than third side.

if (a < 0 || b < 0 || c < 0 ||

(a + b <= c) || a + c <= b ||

b + c <= a)

{

cout << "Not a valid trianglen";

exit(0);

}

float s = (a + b + c) / 2;

return sqrt(s * (s - a) *

(s - b) * (s - c));

}

// Driver Code

int main()

{

float a = 3.0;

float b = 4.0;

float c = 5.0;

cout << "Area is " << findArea(a, b, c);

return 0;

}

// This code is contributed

// by rathbhupendra

Similar questions