Learn Programming and technology with ease @ developerpublish.com

HomeC ProgrammingC Program to Find the Area of a Triangle

# C Program to Find the Area of a Triangle

This C program calculates the area of a triangle using the formula: area = 0.5 * base * height.

## Problem statement

Write a C program to find the area of a triangle using the given base length and height.

## C Program to Find the Area of a Triangle

```#include <stdio.h>

int main() {
printf("Program to calculate the area of a triangle\n");

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

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

float area = 0.5 * base * height;

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

return 0;
}```

## How it works

1. The program starts with an introduction message.
2. It declares two variables: `base` and `height` to store the base length and height of the triangle, respectively.
3. It prompts the user to enter the base length of the triangle.
4. The user enters the base length, which is read using the `scanf` function and stored in the variable `base`.
5. It prompts the user to enter the height of the triangle.
6. The user enters the height, which is read using the `scanf` function and stored in the variable `height`.
7. The program calculates the area of the triangle using the formula `area = 0.5 * base * height` and stores the result in the variable `area`.
8. Finally, it displays the area of the triangle using the `printf` function.

## Input / output

Share:

### You May Also Like

#### C Program to Find Volume and Surface Area of Sphere

This C program calculates the volume and surface area of a sphere using its radius. A sphere is a three-dimensional...

#### C Program to Convert Roman Number to Decimal Number

This C program converts a Roman numeral to a decimal number. Roman numerals are a system of numerical notation used...

#### C Program to Calculate the Value of sin(x)

This C program calculates the value of sin(x) using the Taylor series expansion. The Taylor series expansion is a mathematical...