Write a C program to input base and height of a triangle from user and find area of the triangle given. How to find area of a triangle whose base and height is given by user in C programming. C program to calculate area of a triangle if base and height of the triangle are given.

Input base of the triangle: 10

Input height of the triangle: 15

Output area = 75 sq. units

Happy coding ;)

**Example:**Input base of the triangle: 10

Input height of the triangle: 15

Output area = 75 sq. units

### Required knowledge

Fundamentals of C, Data types, Talking user input in C#### Area of triangle

Area of triangle can be given by formula: (base * height) / 2.### Program

/** * C program to find area of a triangle if base and height are given */ #include <stdio.h> int main() { float base, height, area; // Reads base and height of the triangle from user printf("Enter base of triangle: "); scanf("%f", &base); printf("Enter height of triangle: "); scanf("%f", &height); // Calculates area of triangle area = (base * height) / 2; printf("Area of the triangle = %.2f sq. units.", area); return 0; }

Output

Enter base of triangle: 10

Enter height of triangle: 15

Area of the triangle = 75.00 sq. units.

Enter height of triangle: 15

Area of the triangle = 75.00 sq. units.

**Note:**%.2f is used to print the area only up to two decimal places. You can also use simply %f to print area up to six decimal places.

Happy coding ;)

### You may also like

- Basic programming exercises index.
- C program to calculate area of equilateral triangle.
- C program to find angle of a triangle if its two angles are given.
- C program to check whether a triangle is valid or not if all its angles are given.
- C program to check whether a triangle is valid or not if all its sides are given.
- C program to check whether a triangle is Equilateral, Isosceles or Scalene triangle.
- C program to find area of rectangle.
- C program to find diameter, circumference and area of circle.
- C program to convert length from centimeter to meter and kilometer.
- C program to convert temperature from Fahrenheit to Celsius.
- C program to convert days to years, weeks and days.
- C program to calculate total, average and percentage.
- C program to calculate Simple Interest.
- C program to calculate Compound Interest.

< code >< pre > -- Your source code -- < /pre >< /code > (Remove spaces from pre and code tags).