Skip to content
Exercise Problems · Q1

Q.Write a C program to find area of a triangle when its three sides are given.

Karnataka PUCTextbookLongImportance★★★★★est
1% · 2/154 Questions
✓ Free question

[!TLDR]

Use Heron's formula area = sqrt(s(s-a)(s-b)(s-c)) with s = (a+b+c)/2; sides 3,4,5 give area 6.00.

When only the three sides of a triangle are known (not the base and height), Heron's formula is the direct route to the area. First compute the semi-perimeter s = (a + b + c)/2, then area = sqrt(s(s-a)(s-b)(s-c)). The program reads the three sides as float, applies the formula using the library sqrt() from math.h, and prints the area to two decimal places.

[!ANSWER]

#include <stdio.h>
#include <math.h>
void main()
{
    float a, b, c, s, area;
    printf("Enter the three sides of the triangle\n");
    scanf("%f%f%f", &a, &b, &c);
    s = (a + b + c) / 2.0;                       /* semi-perimeter */
    area = sqrt(s * (s - a) * (s - b) * (s - c));
    printf("Area of the triangle = %.2f\n", area);
}

Expected output:

Enter the three sides of the triangle
3 4 5
Area of the triangle = 6.00

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.