2

(713
Views)

I want to find out the area of the triangle in C programing language. I am learning C language. I am a beginner in C. How can I find out the area of the triangle in C language?

arnabisaha (2.2K Points)

in C Language 2 Answers

1

The area of the triangle is A=hb/2. This is the mathematics formula to find out the area of the triangle. We can convert it to the C programming language. First of all, understand the formula.

Area of the triangle A = hb/2.

A represents the area of the triangle.

h represents the height of the triangle.

b denotes the base of the triangle

Now, convert it to C programming language.

We can use the math header files in the C program. To get the exact area of the triangle in the C program, you need to convert into C programming.

There are three variables like a,b, h.

a = Area of the triangle in the C program.

b= Base of the triangle in the C program.

h = Height of the triangle in the C program.

Let's create an example in C language -

```
#include <stdio.h>
#include<math.h>
int main()
{
float a;
float b=4.0;
float h=4.0;
a=h*b/2;
printf("Area of triangle= %.2f\n", a);
return 0;
}
```

Compile and execute the C program. You will get the area of the triangle as output.

Area of triangle= 8.00

Comment

vishalrana1(7.3K Points)

answered 0

Mathematics is the base of every programming to execute the code in the right way. You are mentioned to find out the area of the triangle.

Let's understand with the steps -

1. Area of the triangle - A=bh/2.

2. Think about the variable in the formula. You must create the variables in the C programming language. There are three variables in that mathematics formula.

3. Declare three variables in the C program. We assign the data type with the variable in the C language

```
float a;
float b;
float h;
```

4. Define the variable value.

```
b=4.5;
h=3.6;
```

6. Convert area formula in the C language.

`a=h*h/2; `

7. Print the value of a.

This is the way to find out the area of the triangle in the C programming language.

Comment

Your Answer

You can post your answer after