Computer Science, asked by abhiramchikkala, 1 year ago

Write a program to calculate the area and perimeter of a triangle given the length of

three sides. (Area = square root of (s(s-a)(s-b)(s-c)), where s=(a+b+c)/2 and Perimeter =

(a+b+c))​

Answers

Answered by priyansh9397
19

Answer:

Area Of a Triangle in C

If we know the length of three sides of a triangle, we can calculate the area of a triangle using Heron’s Formula

Area of a Triangle = √(s*(s-a)*(s-b)*(s-c))

s = (a + b + c)/2 (Here s = semi perimeter and a, b, c are the three sides of a triangle)

Perimeter of a Triangle = a+b+c

C Program to find Area of a Triangle and Perimeter of a Triangle

This program for the area of a triangle in c allows the user to enter three sides of the triangle. Using those values, we will calculate the Perimeter of a triangle, Semi Perimeter of a triangle, and then Area of a Triangle.

/* C Program to find Area of a Triangle and Perimeter of a Triangle */

#include<stdio.h>

#include<math.h>

int main()

{

float a, b, c, Perimeter, s, Area;

printf("\nPlease Enter three sides of triangle\n");

scanf("%f%f%f",&a,&b,&c);

Perimeter = a+b+c;

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

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

printf("\n Perimeter of Traiangle = %.2f\n", Perimeter);

printf("\n Semi Perimeter of Traiangle = %.2f\n",s);

printf("\n Area of triangle = %.2f\n",Area);

return 0;

}

ANALYSIS:

Step 1: User will enter the three sides of the triangle a, b, c.

Step 2: Calculating the Perimeter of the Triangle using the formula P = a+b+c.

Step 3: Calculating the semi perimeter using the formula (a+b+c)/2. Although we can write semi perimeter = (Perimeter/2) but we want to show the formula behind. That’s why we used the standard formula

Step 4: Calculating the Area of a triangle using Heron’s Formula:

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

The sqrt() function is the math function, used to calculate the square root

Explanation:

Mark as brain list

Answered by shilpiguptacsit
0

Explanation:

class triangle

{

public static void main( double a, double b, double c)

{

double ar, p, s

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

ar=Math.sqrt(s×(s-a)×(s-b)×(s-c));

p=a+b+c;

System.out.println("Area="+ar);

System.out.println ("Perimeter ="+p)

}

}

Similar questions