• Register
Welcome to Techno Smarter QA, Questions, Answers Community
Welcome to Techno Smarter Q&A, where you can ask questions and receive answers from other members of the community. Ask the tech & programming Question that you want. Guests Posting are allowed.
+2 votes
11 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?
in C Language by (1.8k points) 1 5 26

2 Answers

+1 vote

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. 

Create a program to find out the area of the triangle in C 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  

 

by (7.1k points) 4 20 46
0 votes

The mathematics is the base of every programming to execute the code in 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 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.

 

 

by (5.1k points) 4 15 45
...