  Get free ebooK with 50 must do coding Question for Product Based Companies solved
Fill the details & get ebook over email  Thank You!
We have sent the Ebook on 50 Must Do Coding Questions for Product Based Companies Solved over your email. All the best!

# Area of Triangle Program in C

Last Updated on April 25, 2023 by Prepbytes A triangle is a polygon with three sides and three angles. It is a basic two-dimensional shape that can be found in various geometrical and real-life situations programs and calculates the area of a triangle using the base and height of the triangle, which are typically input by the user at runtime

## Area of Triangle Program in C

A program to calculate the area of triangle program in c involves taking the input of the base and height of the triangle from the user, calculating the area using the formula, and displaying the result. It is a simple program that uses basic arithmetic operations and can be easily implemented in C.

The formula of an area of triangle program in C

``Area = (base * height) / 2``

### Algorithm for Area of Triangle Program in C

Here is an algorithm for the area of a triangle program in C:

• First declare three variables of type float for the base, height, and area.
• Allow the user to input the values of the base and height.
• Read the values of base and height from the user.
• Calculate the area of the triangle using the formula: area = 0.5 base height
• Print the value of the area on the screen.
• End the program.

### Example for Area of Tiangle Program in C

```#include <stdio.h>

int main() {
float base, height, area;

printf("Enter the base of the triangle: ");
scanf("%f", &base);

printf("Enter the height of the triangle: ");
scanf("%f", &height);

area = (base * height) / 2;

printf("The area of the triangle is: %.2f\n", area);

return 0;
}```

An explanation for an area of triangle program in C
The area of triangle program in c uses the formula (base * height) / 2 to calculate the area of a triangle. It prompts the user to enter the values of the base and height of the triangle and reads them using scanf() function. The area is then calculated using the formula and stored in the area variable. The printf() function displays the triangle area on the screen with two decimal places using the format specifier "%.2f". This program is simple yet effective in demonstrating the use of basic C functions for performing arithmetic operations and taking user input.

Conclusion
In conclusion, the area of triangle program in c is a basic yet essential program that calculates the area of triangle program in C by using the formula (base * height) / 2. It takes input from the user, performs the calculation, and displays the output on the screen. This program is helpful in various fields such as engineering, architecture, and physics.

Q1. What is the significance of the formula used to calculate the area of triangle program in C?
Ans: The formula to calculate the area of triangle program in C is significant because it is a fundamental concept in geometry used in various fields such as engineering, architecture, and physics. The area of a triangle is an essential parameter used in designing and evaluating geometric shapes.

Q2. What are the data types used in the area of triangle program in C?
Ans: In the area of triangle program in C, the float data type is commonly used to store the values of the base, height, and area of the triangle. The float data type is used to represent numbers with decimal points.

Q3. How does the scanf function work in the area of triangle program in C?
Ans: The scanf function is used to read input from the standard input (keyboard) in the area of triangle program in C. It takes the address of the variable where the input is to be stored as an argument. For example, in the line scanf("%f", &base);, the "%f" format specifier is used to read a floating-point number and the & operator is used to get the address of the base variable where the input is to be stored.

Q4. What is the significance of the ".2" in the printf function in the area of triangle program in C?
Ans: The ".2" in the printf function is a format specifier that specifies the precision of the decimal places to be displayed. In this case, ".2" means that the program will display the area with two decimal places. This is useful when working with calculations that involve decimal points, as it allows for more accurate output.

Q5. What is the purpose of the return statement in the main function in the area of triangle program in C?
Ans: The purpose of the return statement in the main function in the area of triangle program in C is to indicate the status of the program’s execution to the operating system. A return value of 0 typically indicates that the program has been executed successfully, while a non-zero value indicates an error.